Question by
davide2001 · Oct 23, 2015 at 06:06 PM ·
javascriptfpsgunfirerate
fireRate javascript?
I'm making a miniagme, were, you can shoot. I use this Firerate stript, and I don't know why it doesn't work: the scene start, I shot one time, and the x become equal to 0.511. I don't know why it doens't works! can you help me please? this is an example, like my real script:
#pragma strict
var spownPoint : Transform;
var bullet : GameObject;
var bool : boolean;
var force : int=1000;
var x : GameObject;
var z : float;
var y :float;
function Start ()
{
}
function Update ()
{
if(Input.GetKey(KeyCode.E)&&Time.deltaTime>z)
{
z = Time.deltaTime+y;
shot();
}
}
function shot()
{
var x = Instantiate(bullet, spownPoint.position, spownPoint.rotation);
x.GetComponent.<Rigidbody>().AddForce(x.transform.forward*forza);
}
Comment
Best Answer
Answer by SniperEvan · Oct 24, 2015 at 06:57 AM
Time.deltaTime is the time that occurred between frames. I think you should be using Time.time instead (in both spots) Let me know if that fixes it.
Thanks, now I use another script, becouse it is better
this is the script
#pragma strict
var posizione : Transform;
var proiettile : GameObject;
var bool : boolean;
var forza : int=1000;
var canFire : boolean;
var Firerate : float;
function Start ()
{
}
function Update ()
{
if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.E)&&canFire==false)
{
Sparo();
}
}
function Sparo()
{
canFire=true;
var x = Instantiate(proiettile, posizione.position, posizione.rotation);
x.GetComponent.<Rigidbody>().AddForce(x.transform.forward*forza);
yield WaitForSeconds (Firerate);
canFire=false;
}