Shooting script problem.

Ok. Im not bad with scripting and whatever. But this is my script. I Keep Getting these few errors. The Errors are:
(Filename: Assets/Scripts/shooting.js Line: 35)

Assets/Scripts/shooting.js(36,25): BCE0043: Unexpected token: :.

(Filename: Assets/Scripts/shooting.js Line: 36)

Assets/Scripts/shooting.js(36,26): UCE0001: ‘;’ expected. Insert a semicolon at the end.

(Filename: Assets/Scripts/shooting.js Line: 36)

When i put them in it says That it doesn’t need to be there.I would Appreciate any help.

#pragma strict
var projectile : Rigidbody;
var speed : float;
var Spawn : Transform;
var Nextshoot : float;
var Projectiledelete : float;
var Reloadtime : float = 2;
var AmmoInMag : float = 50;
static var AmmoLeft : float;
private var CanFire = true;
function Start () {
AmmoLeft = AmmoInMag;

}

function Update () {
if (AmmoLeft == 0)
{
Reload();
}
if (AmmoLeft < 0){
AmmoLeft = 0;
}
if (CanFire == true){
if (Input.GetButton(“Fire1”)){
if(AmmoLeft > 0){
BroadcastMessage(“FireAnim”);
if (Time.time>Nextshoot){
Nextshoot=Time.time+0.2;
var instantiatedProjectile : Rigidbody = Instantiate(projectile,Spawn.position, Spawn.rotation );
instantiatedProjectile.velocity = transform.TransformDirection( Vector3( speed, 0, 0 ) );
AmmoLeft -= 1;
audio.Play();
}
function Reload (){
CanFire == false;
BroadcastMessage(“ReloadAnim”);
yield WaitForSeconds(Reloadtime);
CanFire == true;
}

if(Time.time>Projectiledelete){
Projectiledelete=Time.time+0.5;
Destroy(GameObject.Find(“Projectile(Clone)”));
}

}
}
}

You cannot put a function inside of a function. You had function Reload() inside of function Update(). You also only use double equals sign “==” when you’re asking if something is equal to something else. To SET the boolean, you only use 1 equals sign (you had Canfire == true instead of Canfire = true. You did use this correctly when using an if statement - if(Canfire == true)… You can also say if(Canfire), and if you want to check if it is false, use an exclamation point “!” in front of the statement, ! meaning NOT. So you could say if(!Canfire) instead of if(Canfire == false). Here is your fixed code :slight_smile:

#pragma strict

var projectile : Rigidbody;
var speed : float; 
var Spawn : Transform; 
var Nextshoot : float; 
var Projectiledelete : float; 
var Reloadtime : float = 2; 
var AmmoInMag : float = 50;
static var AmmoLeft : float;
private var CanFire = true; 

function Start () 
{ 
	AmmoLeft = AmmoInMag;
}

function Update () 
{ 
	if (AmmoLeft == 0) 
	{ 
		Reload();
	}
	
	if (AmmoLeft < 0)
	{ 
		AmmoLeft = 0; 
	} 
	
	if (CanFire)
	{ 
		if (Input.GetButton("Fire1"))
		{ 
		
			if(AmmoLeft > 0)
			{ 
				BroadcastMessage("FireAnim");
			
				if (Time.time>Nextshoot)
				{ 
					Nextshoot=Time.time+0.2; 
					var instantiatedProjectile : Rigidbody = Instantiate(projectile,Spawn.position, Spawn.rotation ); 
					instantiatedProjectile.velocity = transform.TransformDirection( Vector3( speed, 0, 0 ) ); AmmoLeft -= 1; audio.Play(); 
				} 
				
				if(Time.time>Projectiledelete)
				{
					Projectiledelete=Time.time+0.5; Destroy(GameObject.Find("Projectile(Clone)")); 
				}
			} 
		} 
	}
}

function Reload()
{ 
	CanFire = false; 
	BroadcastMessage("ReloadAnim"); 
	yield WaitForSeconds(Reloadtime); 
	CanFire = true; 
}

Yes it helped majorly thankyou.