- Home /
AI explode when it is close to you
How can I make the AI car explode when it is near you? and how can I make it so the player car have life?
Answer by Starkid225 · Feb 17, 2013 at 10:02 PM
I would recommend using Vector3.Distance found here in the Unity Scripting Documentation. This will return the distance between for example you and the enemy. You can then use this to check if its less then 2 or something then use Destroy() to destroy the game object, deal damage to the player, and possibly even display a small explosion. Hope this helps. As for making the player car have health you could create a Float variable is a player script and attach it to the player car game object (use MonoBehavior) and have a function to adjust that variable. Hope that helps...
Your answer
![](https://koobas.hobune.stream/wayback/20220613092853im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
ENEMY HEALTH BAR 1 Answer
How can I more optimize My AI Script 0 Answers
problem with LookRotation on simple AI 0 Answers
Tennis game like Grand slam tennis 1 Answer
How do I stop an Enemy NavMeshAgent from intersecting the player model? 3 Answers