OnCollisionEnter不知何故不起作用

时间:2017-03-22 00:38:06

标签: c# unity3d

我正努力让球员接触到一个名为" ballInAir"它减少了屏幕右上角的生命计数。它不起作用。这是代码:

using UnityEngine;
using UnityEngine.UI;
public class livesScript : MonoBehaviour {
public Text livesText;
public float lives;
// Use this for initialization
void Start () {
    livesText = GameObject.FindWithTag("lives").GetComponent<Text>();
    lives = 4;
}

// Update is called once per frame
void Update () {

    livesText.text = "Lives: " + lives;
}

void OnCollisionEnter(Collision bol)
{
    if (bol.gameObject.name == "ballInAir")
    {

        lives = lives - 1;

    }

}

}

截图: http://#########.org/

球的刚体: Screenshot of game

玩家的刚体: Rigidbody of the Ball

播放器预制件的结构:Rigidbody of player

预制件的胶囊部分,附加到脚本的部分以及我想要检测与球碰撞的部分:enter image description here

enter image description here

预制件的Firstpersoncontroller部分:enter image description here

0 个答案:

没有答案