当玩家死亡时,它是减去2颗心,而不是1颗心。玩家有5颗心,我放了一个调试日志,当他死一次时显示“43”,然后显示“21”和等等。这是我的脚本:如果是生命管理器
void Awake()
{
instance = this;
}
void Start()
{
livesTxt.text = "Lives - " + playerLives.ToString();
}
public void Lives()
{
playerLives -= 1;
Debug.Log(playerLives);
livesTxt.text = "Lives - " + playerLives.ToString();
}在这里它运行脚本
public void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "Water")
{
Vector3 randomPosition = new Vector3(Random.Range(minX, maxX), Random.Range(minY, maxY), Random.Range(minZ, maxZ));
player.transform.position = randomPosition;
LivesScore.instance.Lives();
}
}我怎么能减一颗心呢?
发布于 2021-09-09 06:24:35
OnTriggerEnter()方法似乎被调用了两次。我认为这可能是一个解决方案。
简单地说:如果你使用的是球体或胶囊对撞机,它可以同时用两点触碰触发对撞机。这可以通过使用布尔检查来修正。
(直接从连系职位取走)
void OnTriggerEnter (Collider hitObject)
{
if(isColliding) return;
isColliding = true;
// Rest of the code
}
void Update(){
isColliding = false;
}https://stackoverflow.com/questions/69110079
复制相似问题