2016-10-05 24 views
0
public class green : MonoBehaviour 
{  
    // Use this for initialization 
    void Start() 
    { 

    } 

    // Update is called once per frame 
    void Update() 
    { 

    } 

    void OnTriggerEnter2D(Collider2D other) 
    { 

     if (other.gameObject.tag == "BLUE") 
     { 
      Destroy(other.gameObject); 

      gm.mylife -= 1; 
     } 
    } 
} 

public class gm : MonoBehaviour 
{  
    public GameObject blue; 
    static public bool tr = false; 
    public Text life; 
    public static int mylife = 0; 

    void Start() 
    { 
     makebox();  
    } 

    void makebox() 
    { 
     StartCoroutine("timedelay"); 
    }    

    IEnumerator timedelay() 
    { 
     yield return new WaitForSeconds(3f); 
     Debug.Log("sdfaDF"); 
     GameObject br = Instantiate(blue, new Vector3(-6, -2, 0), Quaternion.identity) as GameObject; 
     makebox(); 
    } 

    void Update() 
    { 
     life.text = (mylife.ToString()); 

    } 
} 

我做了一個藍色的盒子,當它碰到東西並且有-1分時被銷燬。 它是在(-2,2)的位置。 然後我做了一個預製。但預製不起作用。它只是在與原點相同的位置創建的。 我想讓我的預製摧毀並且也是-1。 我該如何解決它? 請幫我...預製不同於它的原點

回答

0

您在產卵相同位置的物體所有的時間:

GameObject br = Instantiate(blue, new Vector3(-6, -2, 0), Quaternion.identity) as GameObject; 

相反,你應該給一個新的位置,每次是這樣的:

public Vector3 offSet = new Vector3(2,0,0); 
Vector3 pos; 
IEnumerator timedelay() 
{ 
    yield return new WaitForSeconds(3f); 
    Debug.Log("sdfaDF"); 
    GameObject br = Instantiate(blue, pos, Quaternion.identity) as GameObject; 
    pos += offSet; 
    makebox(); 
} 
+0

謝謝你的幫助...但是,我給了延遲...也許它可以解決,給克隆的預製標籤...我檢查克隆的預製沒有標籤... ㅠㅠ – fluentparrot

0

遊戲對象blue = Instantiate(bluep); blue.tag =「BLUE」;

我解決了在腳本給對象標記。