- Home /
Question by
DrunkGamer · Aug 15, 2013 at 02:42 PM ·
javascripterrorfollow
Problems with java script.
Hello people, I'm still learning coding (i know basic HTML5 scripting, but i find javascript a bit more complicated than it (but less than C# or boo) I made this script so an object follows the player but stops following it when the player sees it. IDK what my mistake is, and i what to know your opinion. I'm not asking you to do all the script for me (If you do that i will never learn :P) i just want to know where my mistake is.
#pragma strict
var leader : Transform;
var follower : Transform;
var speed : float =5;
function Start () {
}
function Update(){
function OnBecameVisible() {
enabled = true;
follower.LookAt(leader);
follower.Translate(speed*Vector3.forward*Time.deltaTime);
}
}
Comment
Best Answer
Answer by Eric5h5 · Aug 15, 2013 at 02:46 PM
You can't put functions inside other functions.
Oh stupid me, thank you. Every time i ask a stupid question like this one probably a cute cat dies :P
I think i fixed it now.
#pragma strict
var leader : Transform;
var follower : Transform;
var speed : float =1;
function OnBecameInvisible() {
enabled = true;
follower.LookAt(leader);
follower.Translate(speed*Vector3.forward*Time.deltaTime);
}