0
votes

I have problem with 2d game in unity. There is sprite named Player with box collider 2D, rigidbody, moving... There is another sprite with two box colliders 2D. First isn't trigger, second is trigger. This sprite has this code:

private void OnTriggerEnter2D(Collider2D other)
{
    if(other.CompareTag("Player"))
    {
        Debug.Log("Player in range");
    }
    
}

private void OnTriggerExit2D(Collider2D other)
{
    if(other.CompareTag("Player"))
    {
        Debug.Log("Player left range");
    }
}

enter image description here This is player enter image description here This is game object

I need to make that player in range of that object. This is only for debug but it's not working. I don't have any idea how to fix it. I tried docs but I don't know, I'm beginner. Thanks for help.

1
please use the correct tags ... unityscript is or better was a JavaScript flavor like custom language used in early Unity versions and is long deprecated by now ... your code is clearly c# - derHugo

1 Answers

1
votes

I see you are new to Unity. You have confused names of things. Let it put it straight for you.

  • Your Game Object is named Player
  • The Game Object's tag is Untagged
  • The Game Object has a Component called Sprite Renderer
  • The Sprite Renderer has a Sprite (the image) called playerDown_0

Your problem is that your game object Player does not have a tag.

enter image description here