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"); } }
This is player
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.
11 Answer
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.