# Shooting robot problem

**URL:** <https://forums.kodeco.com/t/shooting-robot-problem/20887>\
**Category:** Unity Games by Tutorials\
**Created:** [October 7, 2016, 9:00pm UTC](https://forums.kodeco.com/t/shooting-robot-problem/20887 "2016-10-07T21:00:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tekodragoon](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/tekodragoon/32/69716_2.png) [@tekodragoon](https://forums.kodeco.com/u/tekodragoon)\
**Post date:** [October 7, 2016, 9:00pm UTC](https://forums.kodeco.com/t/shooting-robot-problem/20887/1 "2016-10-07T21:00:39Z")

</div>

I think something missing in the Fire() function.  
Even there is no ammo the script continue to calculate the Ray and shoot robot.  
I modify like this to avoid this.

```
protected void Fire() {
        if (ammo.HasAmmo(tag)) {
	    GetComponent<AudioSource>().PlayOneShot(liveFire);
	    ammo.ConsumeAmmo(tag);
	} else {
	    GetComponent<AudioSource>().PlayOneShot(dryFire);
	}
	GetComponentInChildren<Animator>().Play("Fire");
	
        //if there is no ammo don't shoot
        if (!ammo.HasAmmo (tag))
	    return;

	Ray ray = Camera.main.ViewportPointToRay(new
        Vector3(0.5f, 0.5f, 0));
	RaycastHit hit;
	if (Physics.Raycast(ray, out hit, range)) {
		processHit(hit.collider.gameObject);
	}
}

```
