- Home /
about loop transforming objects
i have many doors in my game..i just want to make moving these door in a loop..i mean after i pass a trigger first i want to move door then after 5 or 10 minutes i want to move again same door to the another location..how can i do that..thanks for answer
Answer by FlaSh-G · May 06, 2020 at 05:28 AM
For doing things with pauses inbetween, coroutines are your friend:
public void DoTwoThings()
{
StartCoroutine(DoTwoThingsCoroutine());
}
private IEnumerator DoTwoThingsCoroutine()
{
DoOneThing();
yield return new WaitForSeconds(60 * 10); // wait 10 minutes
DoAnotherThing();
}
i am new at unity and also my english is not perfect can you explain clearly ? please ?
A coroutine is a method that can be paused for one or more frames before it continues to run. It is set up by
$$anonymous$$aking a method that returns
IEnumerator
and has at least one yield statement (which is the line where the method will be paused)Calling
StartCoroutine
and passing that IEnumerator as a parameter (call the coroutine method in the brackets of StartCoroutine)
Here's some code you can paste into a fresh component to try it out:
private void Start()
{
StartCoroutine(SayHello());
}
private IEnumerator SayHello()
{
Debug.Log("Hello!");
yield return new WaitForSeconds(2);
Debug.Log("Hello again!");
}
This will print "Hello!" in the console, then wait for two seconds, then print "Hello again!" in the console.
Your answer
![](https://koobas.hobune.stream/wayback/20220612233039im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to pick up objects 1 Answer
A transform.position to act as a Vector3 1 Answer
What would you do with essential items? 1 Answer
My script doesnt respond what i wrote HELP!!! 0 Answers
How to turn object into a particle system and back? 0 Answers