- Home /
reloadtime
hello i dont know how i make a reloadtime on this script can u help me
var projectile : Transform;
var speed = 1;
var barrel : Transform;
var shootSound: AudioClip;
var shots : int = 0 ;
var maxShots : int = 8 ;
var reloadSound: AudioClip;
function Update () {
if ( Input.GetButtonDown ("Fire1") && shots < maxShots){
audio.PlayOneShot (shootSound);
clone = Instantiate(projectile, barrel.position, barrel.rotation);
clone.rigidbody.velocity = barrel.TransformDirection( Vector3 (0, 0, speed));
shots ++;
}
else if (shots >= maxShots && Input.GetKeyDown(KeyCode.R))
{
audio.PlayOneShot (reloadSound);
shots = 0;
}
}
Comment
lmgtfy.com/?q=unity+reload+script
or you could look at the related questions for reload. there are millions.
Best Answer
Answer by deltamish · Apr 14, 2013 at 04:02 PM
Hi try using yield WaitForSeconds
public var ReloadTime:float = 2;
function Update () {
if ( Input.GetButtonDown ("Fire1") && shots < maxShots){
audio.PlayOneShot (shootSound);
clone = Instantiate(projectile, barrel.position, barrel.rotation);
clone.rigidbody.velocity = barrel.TransformDirection( Vector3 (0, 0, speed));
shots ++;
}
else if (shots >= maxShots && Input.GetKeyDown(KeyCode.R))
{
Reload();
}
}
function Reload(){
audio.PlayOneShot (reloadSound);
yield WaitForSeconds(ReloadTime);///Wait 2(ReloadTime) seconds before continuing
shots = 0;
}
Your answer
Follow this Question
Related Questions
After scene reload script stopped working. 1 Answer
put a 2 second delay for each bullet? 1 Answer
Timer not working as expected. 1 Answer
Reset timeSinceLevelLoad? 0 Answers
Turret script TT longer reloading 2 Answers