So, I have a script that spawns a rigidbody directly in front of me, and it spawns it as fast as I can press the button with unlimited ammo. I use this script to spawn in shadow clone A.I. of my character, health boxes that the player can throw down like in Battlefield, and other random abilities that I think of on the fly.
However, I don’t want to be able to throw down an infinite amount of things. I want to be able to throw down maybe one or two every couple seconds. I tried doing this with Time.time and Time.deltaTime, however I couldn’t get either of those things to work. I also want to make it into a float so that I can change it in editor if at all possible (however that isn’t a necessary trait)
I am pretty new to scripting, and I am learning and following tutorials at the same time, and not all of it is in c#. Sorry for the inconvenience!
Here is the code:
#pragma strict
var theBullet : Rigidbody;
var Speed = 20;
var coolDown : float;
function Update () {
if (Input.GetKeyDown("f"))
{
var clone = Instantiate(theBullet, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection(Vector3(0, 0, Speed));
Destroy (clone.gameObject, 3);
}
if (Input.GetKeyDown("f") && coolDown == 0)
{
coolDown = 2f;
}
if (coolDown > 0)
{
coolDown -= Time.deltaTime;
}
}
At this point I will accept any help I can get. Anything and everything will be much appreciated!