- Home /
enemy shoots with animation
Hello I would like a hand to assign a script to my enemy. My enemy shoots continuously without stopping. I wish my enemy gunfire along all'animazine that I gave it only when they are in a certain distance from him. That way when I'm away on mìnemico stops and does not shoot in vain. I'm new help me please. Thanks in advance.
Answer by ByteSheep · Jan 14, 2012 at 07:13 PM
Try using the Vector3.Distance function:
var dist : float;
var Enemy : Transform;
function Update () {
dist = Vector3.Distance(transform.position, Enemy.transform.position);
if(dist<10)
{
//Shoot
}
if(dist>10)
{
//don't shoot
}
}
This will check the dist between the variable/object "Enemy" that has been set in the inspector and the object that has the script assigned :)
Your answer
Follow this Question
Related Questions
Enemy Animation Help 0 Answers
How to I vary animations based on proximity? 2 Answers
weapon destroyes enemy without running animation -1 Answers
Gun Animate when it shoots 3 Answers
How to conect distance with animation? 0 Answers