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.

You have a semi-colon (:wink: after the if-statement.

Remove it and it should be fine :slight_smile:

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);   
    }
}