Hi! I’m new in Unity and I’m learning right now. It’s possible I’m doing something stupid, so sorry in advance.
What I actually try to do is call OnTriggerEnter2D in the inherit class and also call it in the class is inherited. But for some reason the OnTriggerEnter2D of the inherited class is it called twice (I used a variable to count to prove it), I don’t know why is callining two times when is triggered.
My code is this:
public class Resource : MonoBehaviour
{
public int number;
protected virtual void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player") && other.isTrigger && (playerWeapon.initialValue == breakeble.initialValue))
{
//I count with this the number of times this is triggered, for now this count 2 every time
number++;
}
}
}
public class Tree : Resource
{
protected Animator anim;
private void Start()
{
anim = GetComponent<Animator>();
}
protected override void OnTriggerEnter2D(Collider2D other)
{
base.OnTriggerEnter2D(other);
}
}
Like you can see this is super basic code, I deleted everything trying to find the error, without luck.