我可以在 Unity 5 中知道谁实例化了对象吗?

Can I know in Unity 5 who Instantiated the object?

是否可以从实例化它的人那里获取实例化对象的信息?

例如假设我们有 objectA:

Instantiate(objectB, gameObject.transform.position, Quaternion.identity);

有没有办法在对象 B 中做这样的事情:

Awake() { var vector = Parent.transform.position };

其中 "parent" 是发起者。

您可以执行以下操作来完成此操作:

// in objectA class's function
GameObject objB = Instantiate(objectB, gameObject.transform.position, Quaternion.identity);
objB.parentPos = transform.position;
// and if you just want to know who Instantiated it, use this line:
objB.parentGameObj = gameObject;

// in objectB class
public Vector3 parentPos;
public GameObject parentGameObj;