# Shooting script problem.

**URL:** https://discussions.unity.com/t/shooting-script-problem/59157
**Category:** Questions & Answers
**Created:** [December 31, 2012, 4:42am UTC](https://discussions.unity.com/t/shooting-script-problem/59157 "2012-12-31T04:42:53Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![deadfroggy](https://avatars.discourse-cdn.com/v4/letter/d/439d5e/32.png) [@deadfroggy](https://discussions.unity.com/u/deadfroggy)
#### Post date: [December 31, 2012, 4:42am UTC](https://discussions.unity.com/t/shooting-script-problem/59157/1 "2012-12-31T04:42:53Z")

</div>

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

}  
}  
}

---

<div class="post-metadata">

### Author: ![clunk47](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@clunk47](https://discussions.unity.com/u/clunk47)
#### Post date: [December 31, 2012, 6:47am UTC](https://discussions.unity.com/t/shooting-script-problem/59157/2 "2012-12-31T06:47:32Z")

</div>

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 🙂

```
#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; 
}

```

---

<div class="post-metadata">

### Author: ![deadfroggy](https://avatars.discourse-cdn.com/v4/letter/d/439d5e/32.png) [@deadfroggy](https://discussions.unity.com/u/deadfroggy)
#### Post date: [January 1, 2013, 12:52pm UTC](https://discussions.unity.com/t/shooting-script-problem/59157/3 "2013-01-01T12:52:33Z")

</div>

Yes it helped majorly thankyou.
