是否可以从实例化对象那里获取信息?
例如,假设我们有 objectA:
Instantiate(objectB, gameObject.transform.position, Quaternion.identity);
有没有办法在objectB中做这样的事情:
Awake() { var vector = Parent.transform.position };
其中“父母”是发起人。
是否可以从实例化对象那里获取信息?
例如,假设我们有 objectA:
Instantiate(objectB, gameObject.transform.position, Quaternion.identity);
有没有办法在objectB中做这样的事情:
Awake() { var vector = Parent.transform.position };
其中“父母”是发起人。
您可以执行以下操作来完成此操作:
// 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;