簡體   English   中英

Unity 3D如何實例化對象位置

[英]Unity 3d how to instantiate object in a certian position

使用UnityEngine; 使用System.Collections;

公共課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預制件,我該怎么做? 提前致謝

根據Instantiate文檔 ,您可以傳入Vector3世界空間位置作為第二個參數。

您還需要傳遞四元數作為其初始旋轉的第三個參數。 Quaternion.identity等同於不旋轉。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM