x


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);

       }

    }
}
more ▼

asked Feb 29 '12 at 01:58 AM

iSlaytheDe4d gravatar image

iSlaytheDe4d
1 2 2 3

(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

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.

more ▼

answered Feb 29 '12 at 02:32 AM

Berenger gravatar image

Berenger
11k 12 19 53

Oh. Sorry! I meant that's what I have so far, without the yield instructions. I tried just writing WaitForSeconds above "Model.SetActiveRecursively", but that failed miserably :3

Feb 29 '12 at 05:38 AM iSlaytheDe4d

Ok then, I don't know if you're familiar with Invoke(), it's a fairly simple function. After the if( Input...), add Invoke( "MyFunction", 2 );. Then inplement my function with the SetActiveRecursively inside. Now when you press the key, it's going to wait 2 secondes and call MyFunction(). Doc

Feb 29 '12 at 06:32 AM Berenger
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4142
x170
x44
x29

asked: Feb 29 '12 at 01:58 AM

Seen: 565 times

Last Updated: Feb 29 '12 at 06:32 AM