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