![](/img/trans.png)
[英]Unity 3D: Instantiate GameObject to specific position on the Parent
[英]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.