Tôi cần khởi tạo và hủy một prefab khi đang chạy. Tôi đã thử các cách sau:Khởi tạo và tiêu diệt Unity3D
public Transform prefab; //I attached a prefab in Unity Editor
Object o = Instantiate(prefab);
//using this I cannot get the transform component (I don't know why) so useless
Transform o=(Transform)Instantiate(prefab);
//gives transform and transform component cannot be destroyed
GameObject o=(GameObject)Instantiate(prefab);
//invalid cast
Vậy làm cách nào để thực hiện điều đó?
Bạn cần phải nghiên cứu một số khái niệm OO. Đó là tất cả về TYPE biến. – Chchwy