- Home /
Problem is not reproducible or outdated
Enemy AI kills player once it gets really close?
Hey guys,
I have a enemy who already is scripted to follow me but once he gets really close he just goes around in circles. I'm wondering if the enemy could kill the player somehow and then it goes red and say try again or something similar to that.
All I need is a script so when the enemy gets atleast a metre away from the player says that you've died and says try again so then when you click it, it'll restart the game. Please help ASAP!
ASAP? Have you somehow gotten yourself into a contractual obligation to deliver this simple implementation without actually knowing how to do it? /peeve
x)
Hold up, don't set me on fire, I'm writing an answer. :)
All vague questions are immediately closed.
please go to forum.unity3d.com to enjoy a big discussion with your issue, and ASAP scripting for you
Answer by Loius · Jan 21, 2013 at 08:45 AM
Have you seen the scripting reference? It's your friend!
You want OnTriggerEnter or OnCollisionEnter (the first one is called when an object enters a 'trigger volume,' and the second is called when two objects bump into each other) to detect the enemy hitting your player. (I'd recommend a Trigger, since you're concerned with distance rather than actual contact).
Text can be done with either a GUI.Label in the OnGUI function, or with Unity's simple 3D Text object from the Object menu.
Once your enemy hits the trigger, set a boolean to true. While that boolean is true, display the 'try again' screen (either enable the text object, or have the OnGUI function switch to displaying the label). You can use a GUI.Button to listen for the player clicking something, or just listen to Input for a mouse button.
You make it sound so easy though, i'm no good at scripting, is there a script?
Follow this Question
Related Questions
Enemy Combat AI 1 Answer
Enemy AI Script Glitch 0 Answers
RAIN AI motion detection limiting the visual sensor 2 Answers
Implementing a few special attacks for a boss 0 Answers
How to make enemy shoot projectile at player when in range? 1 Answer