3

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

例如,假设我们有 objectA:

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

有没有办法在objectB中做这样的事情:

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

其中“父母”是发起人。

4

1 回答 1

1

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

// 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;
于 2015-08-31T15:05:48.430 回答