是否有可能从实例化对象中从实例化对象获取信息?
例如,假设我们有objectA:
Instantiate(objectB, gameObject.transform.position, Quaternion.identity);
在objectB中是否有这样的方法:
Awake() { var vector = Parent.transform.position };
其中“父”是发起者。
发布于 2015-08-31 07:05:48
要做到这一点,您可以执行以下操作:
// 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;
https://stackoverflow.com/questions/31177265
复制