My character have a box colider for the head and a circle collider for the feet. I think that when my character have contact with coin triggers it for 2 times. How can I solve this problem?
Here is my pickup script:
using UnityEngine;
using TMPro;
public class CherryCollector : MonoBehaviour
{
private float cherry = 0; //Actually in my game coins are cherryes
public TextMeshProUGUI textCherry;
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.transform.tag == "Cherry")
{
{
Destroy(collision.gameObject);
cherry++;
textCherry.text = cherry.ToString();
}
}
}
}
Firstly is the box collider(the head) is a trigger and if so does it need to be? Secondly wouldn’t it be better if cherry was an integer? Thirdly maybe it should be cherry++maybe it needs to be ++cherry.
Also, I believe when using floats the syntax would be like private float cherry = 0f;
Sorry I am a beginner so not that experienced just trying to improve though.