- Home /
How to make objects falling down from the top of a scene permanently?
Hey Guys,
I'd like to make some kind of dance-game. The player should move in a specific direction which shall be set by arrows that keep permanently falling down from the top of the whole scene. So is there any advice you can give me especially which logic determinants I should use in the script.
The scene should kinda look like the following photo:
Answer by ZaidesA · Dec 10, 2013 at 07:30 PM
In general, I would advice you to use a Coroutine.
It should look something like this:
IEnumerator CreateArrows()
{
while (true) {
//Create some random arrow here
yield return new WaitForSeconds(secondsToWait);
}
}
You can call your coroutine from the start of MonoBehaviour like this: StartCoroutine( CreateArrows() );
If you use an infinite white loop in your coroutine (like I showed above), you should call 'StopCoroutine' somewhere in your class, otherwise unity will crash.
Hope that helps, if not please e more specific :)
Thanks a lot! I gonna try it. Sorry for not being very specific, it's the first time I'm working with Unity, so it ain't that easy at all.
Is using a Coroutine similar to using an update-medthod? In other words: can I use the update-method the same way like the coroutine, because that seems to be a little easier. ;)
The update function is called around 30 times a second, so everything you write there will also happen 30 times per second, you can't control that.
But in a coroutine, you can decide how much time you want to wait (like in the 'while' loop I showed you), and that's what you need in your case :)
It's pretty hard to start with unity, but once you get the knack of it, it'll be very easy :)