- Home /
yield waitforseconds false/true
function Update () {
if(Input.GetButtonDown("Jump") && !Player1Shoot.MINE && !Player1Shoot.MACHINEGUN && !Player1Shoot.ROCKET && Player1Shoot.SHIELD){
GetComponent(MeshRenderer).enabled = true;
collider.isTrigger = true;
yield WaitForSeconds(15);
GetComponent(MeshRenderer).enabled = false;
collider.isTrigger = false;
}
}
why doesn't it work????
Please review your posts after you make them, and ensure that their formatting is readable.
Answer by efge · Mar 17, 2011 at 10:38 PM
yield statements can only be used in coroutines and if the Renderer is attached to the GameObject you do not have to use GetComponent. Your script could look something like this:
function Update () { if(...){ SwitchTrigger(); } }
function SwitchTrigger() { renderer.enabled = true; collider.isTrigger = true; yield WaitForSeconds(15); renderer.enabled = false; collider.isTrigger = false; }
Answer by Lab013 · Mar 17, 2011 at 09:31 PM
yield doesn't work in coroutines such as Update or OnGUI.
Your answer
Follow this Question
Related Questions
What am I doing wrong? Boolean-Animation Help please 1 Answer
Array SetActive C# Unity 1 Answer
I can't figure out how to enable / disable a trigger. 2 Answers
Set Bool in Inspector to true or False 2 Answers
how false and true player? 1 Answer