Expressions in statements must only be executed for their side-effects.

I have a problem I have not been able to fix by looking at other peoples questions, this has been asked multiple time but i still cant figure out why

Assets/Scripts/BulletShoot.js(13,14): BCE0034: Expressions in statements must only be executed for their side-effects.

var projectile : Rigidbody;
var bulletSpeed = 1;
var ammo = 30;

function Update () {



if (ammo != 0) {
	if (Input.GetButtonUp ("Fire1")) {
	clone = Instantiate(projectile, transform.position, transform.rotation);
	clone.velocity = transform.TransformDirection(Vector3(0, 0, bulletSpeed));
	ammo - 1;
	
	Destroy (clone.gameObject, 5);
	}
}

}

It seems to think that ammo - 1 does nothing but I think it does although I’m not sure

does anyone know why? please explain why instead of just fix the code as I want to learn from my mistakes not just let other people do it for me :slight_smile:

Assuming you’re trying to subtract 1 from ammo, you want either…

ammo = ammo - 1;

or

ammo -= 1;

or

ammo--;

Your original code is not modifying the contents of the variable.

Jeff