Hello. I have written myself a gun script using snippets of code I have found on the internet. I have modified it so that firing and reloading are there own seperate function instead of being in the update function so I have more control over them but I have kept my inputs handled it the update function. I want to know how to call upon my fire and reload functions from my update function
var prefabBullet:Transform;
var shootForce:float;
var shots : int = 0;
var maxShots : int = 100;
var timeBetweenShots = .02;
var shootSound : AudioClip;
var reloadSound : AudioClip;
function Update()
{
if(Input.GetButtonDown("Fire1") && shots < maxShots)
{
//Call fire function
}
else if (shots >= maxShots && Input.GetKeyDown(KeyCode.R))
{
//Call reload function
}
}
function Fire()
{
var instanceBullet = Instantiate(prefabBullet, transform.position, Quaternion.identity);
instanceBullet.rigidbody.AddForce(transform.forward * shootForce);
audio.PlayOneShot(shootSound);
animation.CrossFade("M60Fire");
shots++;
yield WaitForSeconds (timeBetweenShots);
//Call the fire function again
}
function Reload()
{
shots = 0;
animation.CrossFade("M60Reload");
}
Any help is appreciated. Thanks, Zac