- Home /
How to get an object if it touches another object?
I am making a game and in it the player can attack enemies. I'm using:
Physics2D.OverlapCircle(EnemyCheck.position,0.4,whatIsEnemy)
to find if there is an enemy in front of the character however I need to know WHICH enemy is in his range of attack so I can execute the death sequence on the proper enemy. How would one do that? I was thinking about using OnCollisionEnter() but I couldn't figure it out altogether much less figure out how to find what is colliding with it. Thank you for any answers!
Answer by Kiwasi · Aug 06, 2014 at 12:27 AM
The return type of OverlapCircle is a Collider2D.
So you could use:
Collider2D hitTarget = Physics2D.OverlapCircle(EnemyCheck.position,0.4,whatIsEnemy);
Destroy (hitTarget.gameObject);
Your answer
Follow this Question
Related Questions
Is OverlapCircle broken? 0 Answers
Rotate object around certain point using phyics 0 Answers
rigidbody2D.MovePosition() Can't Found 2 Answers
how to calculate force direction on mouse up 1 Answer
Coroutine not working correctly? 1 Answer