C# 摧毁一堵墙c unity3d
我是一个临时摧毁一堵墙的人,玩家处于触发状态,但触发只会激活,玩家将立方体放置在相应的位置,如果立方体位于正确的位置,那么它将被摧毁 这是我的多维数据集触发器脚本 在此脚本中,它将销毁多维数据集和触发器多维数据集 并将墙hp的变量设置为0C# 摧毁一堵墙c unity3d,c#,unity3d,C#,Unity3d,我是一个临时摧毁一堵墙的人,玩家处于触发状态,但触发只会激活,玩家将立方体放置在相应的位置,如果立方体位于正确的位置,那么它将被摧毁 这是我的多维数据集触发器脚本 在此脚本中,它将销毁多维数据集和触发器多维数据集 并将墙hp的变量设置为0 using UnityEngine; using System.Collections; public class triggerwall : MonoBehaviour { public GameObject[] objects; void OnTri
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);
}
然后是墙上的文字
如果is==破坏墙,它将比较变量hp和hpx
我不是一个经验丰富的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);
}
}
}
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);
}
}
}
}
最后,我通过更改墙脚本解决了脚本问题
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);
}
}
}
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);
}
}
}
}
为什么hp是静态的?为什么你要用一个变量来存储0呢?我对c不太了解,我找到了比较两个变量的方法来比较它们,请记住,你只能有一个墙的实例。因为他们将共享相同的hp。至少只要你保持它的静态。这是C只是如果有人需要知道,坦克所有的帮助