Unity3d如何在一定位置实例化对象

时间:2014-08-24 21:50:03

标签: unity3d

使用UnityEngine; 使用System.Collections;

public class playSound:MonoBehaviour {

private bool destructionHasBegun = false;
public Transform BlueKey;


private void OnTriggerEnter()
{
    audio.Play ();
    destructionHasBegun = true;
}

private void Update()
{
    if(destructionHasBegun)
    {
        DestroyWhenSoundComplete();
    }
}

private void DestroyWhenSoundComplete()
{
    if(!audio.isPlaying)
    {
        Destroy(gameObject);
        GameObject textObject = (GameObject)Instantiate(Resources.Load("BlueKey")); 





    }
}

}

我试图在特定位置实例化bluekey预制件我该怎么做?提前谢谢

1 个答案:

答案 0 :(得分:0)

根据Instantiate documentation,您可以将Vector3世界空间位置作为第二个参数传递。

你还需要传入一个Quaternion作为第三个参数进行初始旋转; Quaternion.identity相当于没有轮换。

Vector3 newPosition = new Vector3(0, 0, 0);
Quaternion newRotation = Quaternion.identity;
GameObject textObject = (GameObject)Instantiate(Resources.Load("BlueKey"), newPosition, newRotation);