i am a noob with cs. i have a projectile script that shoots on click, i want to remove that function and add a function that makes it shoot every second. here is the script:
using UnityEngine;
using System.Collections;
public class ShootDemo : MonoBehaviour
{
public Rigidbody projectile;
public float speed = 20;
void Update ()
{
if (Input.GetButtonDown("Fire1")) // this is the part i want to change
{
Rigidbody instantiatedProjectile = Instantiate(projectile,transform.position,transform.rotation)as Rigidbody;
instantiatedProjectile.velocity = transform.TransformDirection(new Vector3(0, 0,speed));
}
}
}
so what i need it for it to shoot WITHOUT CLICKING
float fire_reshoot_track; //defined outside update loop that we use to store when weapon can be fired next
float interval; //defined outside update loop
//inside update loop
if ( fire_reshoot_track < Time.time )
{
Fire ();
fire_reshoot_track = Time.time + interval;
}
I don’t know where I saw this method of tracking refire rates, but I prefer it to other methods I see.