- Home /
why doesent my javascript unity code work
i wont my code to make enemy look at you and chase you but it doesn't work the enemy just stays in that one spot can you tell me whats wrong with this code and if there's something wrong can you re-wright the correct code for me code below
pragma strict
var theplayer : GameObject; var speed : float; var range : int; function Update(){
range=Vector3.Distance(theplayer.transform.position,transform.position);
if(range<99999999999){ transform.LookAt(theplayer.transform.position);
}
if(range<99999999999 && range>15){ transform.Translate(-Vector3.forward*speed);
}
if(range<12){ transform.Translate(-Vector3.forward*speed);
}
}
Answer by Linus · Jul 17, 2013 at 02:25 PM
var theplayer : GameObject;
var speed : float = 10;
var range : float;
function Update(){
Debug.Log('spped:'+speed+' range: '+range);
range = Vector3.Distance(theplayer.transform.position,transform.position);
if(range<99999999999){
Debug.Log('range<99999999999 turning?');
transform.LookAt(theplayer.transform.position);
}
if(range<99999999999 && range>15){
Debug.Log('Debug.Log('range<99999999999') backwards?');
transform.Translate(-Vector3.forward*speed);
}
if(range<12){
Debug.Log('range<12)');
transform.Translate(-Vector3.forward*speed);
}
}
Test that. And have you tripple checked the inspector values
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Trouble with OnCollisionEnter and Exit 1 Answer
Where can I start to learn more about coding? 2 Answers
Is UnityScript the same as JScript? 4 Answers