"Type 'Move1' already has a definition for 'Update()' " help please.

Hello i used this tutorial http://download.unity3d.com/support/Tutorials/2%20-%20Scripting%20Tutorial.pdf

and i got a problem

the tutorial said i should use this script for a camera:

function Update () {
     transform.Translate(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
}

var speed = 5.0;
function Update () {
    	var x = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
    	var z = Input.GetAxis("Vertical") * Time.deltaTime * speed;
    	transform.Translate(x, 0, z);
}

and it worked fine, but then the tutorial said to add a spotlight and to make another script to make the spotlight follow the camera. this is the script:

var target : Transform;

function Update () {
     transform.LookAt(target);
}

but now when i try to attach the script to the spotlight it gives me an error message that says "Script Follow has not finished compilation yet..." and another error message at the bottom of the screen that says Assets/Move1.js(7,10):BCE0089: Type 'Move1' already has a definition for 'Update()'.

i am a noob, i just started to use unity and i dont have much experience with programing, i think the 2 files are conflicting with that update function but i dont really know how to fix this. if someone has a solution please help me and i would appreciate it if you could also explain how your solution works and why.

thank you

LE: i figured it out. i used the function Update() twice in the first script. im sorry for asking a stupid question.

The problem you're having is that in the tutorial, they intended you to replace the first Update with the second version, rather than add it underneath. So your "Move1" script should only have one Update() function:

var speed = 5.0;
function Update () {
    var x = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
    var z = Input.GetAxis("Vertical") * Time.deltaTime * speed;
    transform.Translate(x, 0, z);
}

i.e. delete the lines you currently have above the 'var speed' line.

The reason for this is that in the first example, they are simply introducing you to the idea of modifying a value in the update loop, wheras in the second example, they are demonstrating that it's often important to take into account the framerate when modifying values like this - so the second example is a more complex, but improved version of the intial simple Update() example.

Hi

The resaon you are getting this error is because your scrip Move1 contains two functions named Update, for example, this piece of code would generate the same error:

function Update () {
    //Do something
}

function Update () {
    //Do something else
}

So read that tutorial again and check if they really meant that you should write Update two times in one script.

PS: Please consider posting your code as code and not as just plain text, put 4 spaces before each row to do that, it makes the reading a lot easier ; )

PPS You are too fast Duck, while I was typing my answer you have it already done ; ) ... And now there are two more just one minute after me.

It sounds like you added the second function Update() into the Move.js script. A script can only have 1 Update so you need to add the second script (the camera follow stuff) to a new script like CameraFollow.js.

Move.js

var speed = 5.0; 

function Update () { 
    var x = Input.GetAxis("Horizontal") * Time.deltaTime * speed; 
    var z = Input.GetAxis("Vertical") * Time.deltaTime * speed; 
    transform.Translate(x, 0, z); 
}

CameraFollow.js

var target : Transform;

function Update () {
    transform.LookAt(target);
}

The tutorial actually says to update the script with the second code listing, not add it to the script, so simply remove your first Update function so the script simply reads as this:

var speed = 5.0; 
function Update () 
{ 
    var x = Input.GetAxis("Horizontal") * Time.deltaTime * speed; 
    var z = Input.GetAxis("Vertical") * Time.deltaTime * speed; 
    transform.Translate(x, 0, z); 
}

The way it reads is a little ambiguous so it's an easy mistake to make.