Projectiles (131820)

Could someone help me with this script:

var projectile : Rigidbody;
var speed = 20;

function Update () {

if ( Input.Input.GetMouseButtonUp(0)) {

clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection( Vector3 (0, 0, speed));

Destroy (clone.gameObject, 3);
}} 

Problem here it is that this script create a lot of this objects but i want only one in 2 seconds.
Sorry for bad english

Do you want to add a kind of cooldown between when players can fire or is the script making lots of objects per mouse click?

–

The script is doing lots of object per mouse clic and because of that i want to add some kind of cooldown like you said

–

Make sure that Input.Input.GetMouseButtonUp(0) is actually Input.GetMouseButtonUp(0)

–

Yeah thx :D i find it out after i made this but thx :) But still want to add something like cooldown between shots

–

Thank you a lot :)

–

1 Answer

1

If you want to limit projectiles to once every 2 seconds use the following script

var time=2.0;
function Update () { 
    time = time + Time.deltaTime;
    if (Input.GetMouseButtonUp(0)&&time>=2.0) {
        time=0.0;
        Debug.Log("Click");
    }
}

However it seems that you are accidentally making multiple projectiles per click.

function Update () { 
    if (Input.GetMouseButtonUp(0)) {
        Debug.Log("Click");
    }
}

Only prints once per click. A possible reason for multiple projectiles being created per click is that Update is being called from another script.