- Home /
Delay Invisibility
Hi
I wanted to know how to delay a line of code from activating for a ceratin amount of time
It's function is basically to 1: allow me to swap a weapon out of sight
and 2: when a certain number of seconds have passed make the object invisible.
I have looked into the "WaitForSeconds" type but haven't had much luck in using it.
Ideally It would be great to make a method that delayed the invisibility so I could just call it up as and when i need it (which I tried doing)...
void wait(){}
IEnumerator WaitUp(){
{
yield return new WaitForSeconds(10);
print("im_not_doing_anything");
}
}
So firstly am I using this correctly and is there a better more effective way of pulling this off for instance maybe something like a "wait until animation is played" function similar to the animation "QueMode's" but for invisibility?
Answer by AaronG · Aug 27, 2011 at 01:53 PM
I'm not sure what the issue is. What problem are you having with the coroutine? It looks fine to me.
I guess what you want is a public method which can called from anywhere which will then begins a private coroutine?
// Public method to begin wait coroutine
public void Wait() {
StartCoroutine(wait());
}
private IEnumerator wait() {
yield return new WaitForSeconds(10);
// Do Stuff
}
Answer by melonman · Aug 27, 2011 at 03:09 PM
Thanks that's exactly what i was trying to do and it works nicely.
Your answer
![](https://koobas.hobune.stream/wayback/20220612192747im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Can I make animations snap to a frame? 1 Answer
Blender Animation Looping Delay Problem 2 Answers
Delay on animation 0 Answers
animation delay or wait 4 Answers
Delay the execution of something 1 Answer