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 に答える