x


The code is giving me errors

The code is giving me errors. I was working fine, then I updated Unity to the latest version and now the script is giving me three errors.

#pragma strict

var bullitPrefab:Transform;

function Start () {

}

function Update () {

 if(Input.GetButtonDown("Fire1"));

   {

     var bullit = Instantiate(bullitPrefab, GameObject.Find("spawnPoint").transform.position, Quaternion.identity);

  bullit.rigidbody.AddForce(transform.forward * 3000);   

   }
}

Here are the errors:

  • Assets/Bullet.js(15,6): BCE0043: Unexpected token: var.
  • Assets/Bullet.js(15,9): UCE0001: ';' expected. Insert a semicolon at the end.
  • Assets/Bullet.js(15,9): UCE0001: ';' expected. Insert a semicolon at the end.

I have tried to fix the errors. Please help.

Thank you.

more ▼

asked Jul 19 '12 at 08:25 PM

Sandr0G gravatar image

Sandr0G
40 2 7 10

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You have a semi-colon (;) after the if-statement.

Remove it and it should be fine :)

So the code should be:

#pragma strict

var bullitPrefab : Transform;

function Start () 
{

}

function Update () 
{
    if(Input.GetButtonDown("Fire1")) // Removed - ;
    {
        var bullit = Instantiate(bullitPrefab, GameObject.Find("spawnPoint").transform.position, Quaternion.identity);

        bullit.rigidbody.AddForce(transform.forward * 3000);   
    }
}
more ▼

answered Jul 19 '12 at 08:51 PM

asimov gravatar image

asimov
157 18 36 40

Thank you! It worked.

Jul 19 '12 at 08:59 PM Sandr0G
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1944
x531
x329
x308
x69

asked: Jul 19 '12 at 08:25 PM

Seen: 267 times

Last Updated: Jul 19 '12 at 08:59 PM