0
我是一个完全统一的新手。我想做一个简单的场景,你有三条生命,如果你碰到一个立方体,你就会失去生命。这是我的脚本:OnCollisionEnter统一不会调用函数
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Lives : MonoBehaviour {
public Transform player;
public static int lives;
public Image live1;
public Image live2;
public Image live3;
// Use this for initialization
void Start() {
lives = 3;
live1.enabled = true;
live2.enabled = true;
live3.enabled = true;
}
void Update() {
DisplayOfHearts();
}
public static void Damage() {
lives -= 1;
}
public void OnCollisionEnter(Collision col) {
if (col.gameObject.tag == "cube") {
Lives.Damage();
}
}
public void DisplayOfHearts() {
if (lives == 2) {
live3.enabled = false;
}
else if (lives == 1) {
live2.enabled = false;
}
else if (lives == 0) {
live1.enabled = false;
}
}
}
会发生什么事是玩家无法通过立方体移动,但生命的还是保持三人。有什么我失踪?
告诉我们关于游戏对象 – Bijan
立方体有一个箱子对撞机和一个刚体。 “Is Trigger”功能未打开。播放器(相机)有一个胶囊对撞机,其触发功能也没有打开。 – Robbebeest
该文件表明,只有在其中一个碰撞体上还附加了非运动刚体时才会发送_Collision事件。是这样吗? – Whatever