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
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.