-3
我是一個摧毀牆的臨時文本玩家觸發輸入,但觸發器只激活玩家將立方體放在相應的地方,如果立方體在正確的位置把比它會被銷燬牆..摧毀一個牆c#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 x如果是==的破壞牆壁
以及我沒有經驗的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);
}
}
}
爲什麼hp是靜態的?爲什麼你使用一個變量來存儲0? –
以及我不知道這麼多從C#和我找到解決方案來比較兩個變量來比較它們 –
然後請記住,你只能有1個牆的實例。因爲他們將共享相同的惠普。至少只要你保持靜態。 –