- Home /
WaitForSeconds not working in Input.GetKeyUp?
Hello all. This is my first post on the site, and I'm having some problems with Yield WaitForSeconds. I'm just plain confused and know nothing really about this. I have a script that uses iTween to switch camera positions from first person to third person. I then have another script that deactivates my first person model and activates my third person one. Switching from first to third person works fine, but when I switch back to third person, the first person and third person models activate before the camera zooms in, and I am trying to get it to wait by using WaitForSeconds. Could someone help me? Here's my script so far:
using UnityEngine;
using System.Collections;
public class ModelActive : MonoBehaviour {
public GameObject Model;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKeyUp(KeyCode.Tab)) {
Model.SetActiveRecursively(true);
}
if(Input.GetKeyUp(KeyCode.LeftAlt)) {
Model.SetActiveRecursively(false);
}
}
}
Answer by Berenger · Feb 29, 2012 at 02:32 AM
I don't see any yield instructions. Anyway, I don't think Update can be one. What you could do is create a function that call Model.SetActiveRecursively, and use Invoke to call it later.
Oh. Sorry! I meant that's what I have so far, without the yield instructions. I tried just writing WaitForSeconds above "$$anonymous$$odel.SetActiveRecursively", but that failed miserably :3
Ok then, I don't know if you're familiar with Invoke(), it's a fairly simple function. After the if( Input...), add Invoke( "$$anonymous$$yFunction", 2 );. Then inplement my function with the SetActiveRecursively inside. Now when you press the key, it's going to wait 2 secondes and call $$anonymous$$yFunction(). Doc