- Home /
Wait a fraction of a second within a Function Update()
Not only do I have trouble putting a decimal into the WaitForSeconds () but as well it doesn't want to work in a function Update cuz it says its not a corountine. Basically I'm trying to move a cube once when I press the LMB then after the fraction of a second it moves again. I get all types of problems such as the cube just moving further into space or nothing happening at all.
var time : float = 20;
function Wait(time : float)
{
transform.Translate(Vector3.forward * Time.deltaTime * 1000);
yield new WaitForSeconds(time);
transform.Translate(Vector3.forward * Time.deltaTime * 10);
}
Comment
how are you calling wait()? can it be called many times simultaneously? or is it a cool down?
Answer by ExtremePowers · Nov 02, 2014 at 03:10 PM
Use
yield WaitForSeconds(time);
instead of
yield new WaitForSeconds(time);
var time : float = 20;
function Wait(time : float)
{
if (Input.Get$$anonymous$$ey ("up"))
transform.Translate(Vector3.forward * Time.deltaTime * 1000);
yield WaitForSeconds(time);
transform.Translate(Vector3.forward * Time.deltaTime * 10);
}
Try this:
var time : float = 20.0f;
function Wait(time : float) {
transform.Translate(Vector3.forward * Time.deltaTime * 1000);
yield WaitForSeconds(time);
transform.Translate(Vector3.forward * Time.deltaTime * 10);
}
function Update() {
if (Input.GetButtonDown("up")) {
Wait(0.5);
}
}