我想实例化一个相对于其父对象的对象。更确切地说,我需要在平面的表面上实例化一个立方体,该立方体将被移动和旋转。谢谢你的帮助!
答案 0 :(得分:1)
嗯,这很简单......
public class Spawner : MonoBehaviour
{
public void SpawnChild(GameObject prefab, Vector3 relativePosition, Quaternion relativeRotation = Quaternion.identity)
{
GameObject childObj = Instantiate(prefab);
childObj.transform.parent = transform;
childObj.transform.localPosition = relativePosition;
childObj.transform.localRotation = relativeRotation;
childObj.transform.localScale = Vector3.one;
}
}