Script Error Help

Im getting a Assets/Scrips/BoxLauncher.cs(17,18): error CS1525: Unexpected symbol `if’ error

here’s my script:

using System.Collections;

public class BoxLauncher : MonoBehaviour {

public GameObject[ ] boxPrefabs;

public float fireDelay = 3f;
float nextFire = 1f;

public float fireVelocity = 10f;

void FixedUpdate () {
nextFire -= Time.deltaTime

if(nextFire <= 0); {
//spawn a new box!
nextFire = fireDelay;

GameObject boxGo = (GameObject)Instantiate
( boxPrefabs[ Random.Range(0, boxPrefabs.Length)],
transform.position, transform.rotation);

boxGo.rigidbody2D.velocity = transform.rotation * new Vector2(0, fireVelocity);

}

}
}

Please use code tags.

You miss a semicolon behind

nextFire -= Time.deltaTime

I still have the error :frowning:

Post the new script with code tags.

using UnityEngine;
using System.Collections;

public class BoxLauncher : MonoBehaviour {

    public GameObject[] boxPrefabs;

    public float fireDelay = 3f;
    float nextFire = 1f;

    public float fireVelocity = 10f;


    void FixedUpdate () {
        nextFire -= Time.deltaTime

        if (nextFire -= 0); {
            //spawn a new box!
            nextFire = fireDelay;

            GameObject boxGo = (GameObject)Instantiate
                ( boxPrefabs[ Random.Range(0, boxPrefabs.Length)],
                transform.position, transform.rotation);

            boxGo.rigidbody2D.velocity = transform.rotation * new Vector2(0, fireVelocity);

        }
   
   
    }
}
using UnityEngine;
using System.Collections;

public class BoxLauncher : MonoBehaviour {

    public GameObject[] boxPrefabs;

    public float fireDelay = 3f;
    float nextFire = 1f;

    public float fireVelocity = 10f;


    void FixedUpdate () {
        nextFire -= Time.deltaTime

        if (nextFire -= 0); {
            //spawn a new box!
            nextFire = fireDelay;

            GameObject boxGo = (GameObject)Instantiate
                ( boxPrefabs[ Random.Range(0, boxPrefabs.Length)],
                transform.position, transform.rotation);

            boxGo.rigidbody2D.velocity = transform.rotation * new Vector2(0, fireVelocity);

        }
   
   
    }
}

You still miss the semicolon in the line i qouted in my previous post.

1 Like

now im getting this error: Assets/Scrips/BoxLauncher.cs(17,17): error CS0029: Cannot implicitly convert type float' to bool’

using UnityEngine;
using System.Collections;

public class BoxLauncher : MonoBehaviour {

    public GameObject[] boxPrefabs;

    public float fireDelay = 3f;
    float nextFire = 1f;

    public float fireVelocity = 10f;


    void FixedUpdate () {
        nextFire -= Time.deltaTime; 

        if (nextFire -= 0); {
            //spawn a new box!
            nextFire = fireDelay;

            GameObject boxGo = (GameObject)Instantiate
                ( boxPrefabs[ Random.Range(0, boxPrefabs.Length)],
                transform.position, transform.rotation);

            boxGo.GetComponent<Rigidbody2D>().velocity = transform.rotation * new Vector2(0, fireVelocity);

        }
   
   
    }
}

That’s because you’ve got a substraction in the parenthesis of the if, it needs to be an expression that evaluates to true or false.
This

 if (nextFire -= 0);

should be

 if (nextFire <= 0);

Thanks so much!