So I have a script i use for shooting a default sphere in my scene. Each time I press on the screen, I want it to shoot one bullet, then take maybe 1-2 seconds before it will be able to fire again. But each time I fire it, the bullets just double and if you keep on pressing the screen/button, it starts to lag and no mobile device could handle it. Here is the script:
#pragma strict
public var projectile : Rigidbody;
public var shotPos : Transform;
public var shotForce : float = 1000f;
public var moveSpeed : float = 10f;
function Update ()
{
var h : float = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed;
var v : float = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed;
transform.Translate(new Vector3(h, v, 0f));
if(Input.GetButtonUp("Fire1"))
{
var shot : Rigidbody = Instantiate(projectile, shotPos.position, shotPos.rotation);
shot.AddForce(shotPos.forward * shotForce);
}
}
Thanks!