我如何检测到碰撞以添加分数?

问题描述 投票:-1回答:1

当我的播放器触摸该对象时,它应该增加得分但不会消失。我将此代码放在树上。谢谢!

public class LifeTree : MonoBehaviour
{   
    private int contador=0; 
    private ScoreData _scoreData; 

    private void OnCollisionExit(Collision other)
    {
        if (CompareTag("Player") & contador < 4)
        {
            _scoreData.score = _scoreData.score+5;
            Debug.Log("Tree"); 
            contador++;   
        }
    }
}
unity3d collision collider
1个回答
0
投票

因此,首先确保已安装刚体,以便可以识别碰撞。

void OnCollisionEnter(Collision col)
{
  if(col.gameObject.tag == "Player" && contador < 4)
  {
    //detects if the player hit the tree
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.