2016-12-02 4 views
-3

私はプレイヤーがトリガーを入力している間に壁を破壊する温度ですが、トリガーはプレイヤーがそれぞれの場所に立方体を置いているだけであり、立方体が正しいならばそれが破壊される壁よりも場所..壁を破壊するunity3d

これは、キューブとトリガキューブ を破壊し、0

に壁馬力の変数を設定します。このスクリプトでは、キューブ のトリガーのための私のスクリプトです
using UnityEngine; 
using System.Collections; 

public class triggerwall : MonoBehaviour { 

public GameObject[] objects; 

void OnTriggerEnter(Collider other) 
{ 

    destroywall.hp -= 4; 
    Debug.Log ("hp wall"+destroywall.hp); 
    Destroy (gameObject); 
    Debug.Log ("game object"+gameObject); 
    Destroy (other.gameObject); 
    Debug.Log ("other game object"+other.gameObject); 
    //Destroy (gameObject); 
    //Destroy (other.gameObject); 



} 

// Finally, this line destroys the gameObject the player collided with. 
//Destroy(other.gameObject); 

} 

壁スクリプト 次に、変数hpとhpを比較します==壁を破壊

も私は複数のフォームにしようとしているC#の開発を経験していないが、私は、私はすべてのものを破壊ではなく、壁 が、これは壁のスクリプト最後に

using UnityEngine; 
using System.Collections; 


public class destroywall : MonoBehaviour 
{ 
        //Alternate sprite to display after Wall has been attacked by player. 
    public static int hp = 4;       //hit points for the wall. 
    public static int hpx = 0; 

void OnTriggerEnter(Collider other) { 
    if(hp == hpx) { 
     Debug.Log (other.gameObject.tag); 
     Destroy(other.gameObject); 



      } 

    } 
} 
+1

なぜHPスタティックですか?なぜ0を格納するために変数を使用していますか? –

+0

よく私はC#から多くのことを知っていません。私はそれらを比較するための2つの変数を比較するための解決策を見つけました。 –

+1

次に、壁のインスタンスを1つしか持てないことを覚えておいてください。彼らはすべて同じHPを共有します。あなたが静かに保つ限り、少なくとも。 –

答えて

0

ですX場合スクリプトを解決しました壁のスクリプトを変更します

using UnityEngine; 
using System.Collections; 


public class destroywall : MonoBehaviour 
{ 
        //Alternate sprite to display after Wall has been attacked by player. 
    public static int hp = 4;       //hit points for the wall. 
    public static int hpx = 0; 

void OnTriggerEnter ( Collider other ){ 
    if (other.tag == "destroywall") { 
     if (hp == hpx) { 
      Destroy (other.gameObject); 
     } 
    } 
} 


} 
+0

これはC#です。ちょうど誰かが知っている必要があり、助けのために全員にタンク –

関連する問題