#How to wait
1 messages · Page 1 of 1 (latest)
everything
im gonna learn how to do unity in general, get some knowledge of it, then go back to the issue
-
You make a coroutine (code that runs alongside other code)
-
You start that coroutine
-
You wait in that coroutine, then you do what you want
uhh
in my scenario
yield return new WaitForSeconds()
stuff you want to do?
look at the movement code in my scratch game, thats what i want to make
you're lucky I've used scratch and know the language
tell any other programmer that and they'll tell you to fuck off lmao
lol
so any ideas on what to do in that case?
i have the movement script all done, just need to add the wait
which part of the "movement" script do you want
oh
oh man there's a lot of problems with this but ill let it go since you're porting it from scratch
i made it myself and it was the worst script ever
ok i'm assuming your WaitBeforeMove() coroutine is just a yield return new WaitForSeconds
which is a common mistake
the way you have it now, its useless
so ivee been told
when you start a coroutine, its entirely seperate from the rest of that code in the method
you're literally just starting a timer and it doesnt do anything when its done
i want to do
random code
wait 5 seconds
random code
so what you should do is
StartCoroutine(WaitStage());
IEnumerator WaitStage()
{
yield return new WaitForSeconds(5);
if (Random.Range(1, 20) < level)
{
if (area == "stage")
{
moved = true;
timeset = 5;
area = "diningroom";
}
else
{
timeset = 0.1f;
}
}
}
actually
so id have to make a new one every time?
put StartCoroutine() at the bottom
which does what
StartCoroutine
so id put that in the update method?
ok i was hoping not
NEVER start a coroutine in Update
unless ig you know its only going to start once
at the bottom of the coroutine
so id make my big ienumerate and then at the end put StartCoroutine()?
yea
alr
IEnumerator is a coroutine, if you havent figured that out
so i put my big block of code in the ienumerate and then at the end before my } i put a StartCoroutine()
is that correct?
if so, alr, if not, explain
im headin to bed
ye
alr
now how do i implament it so it triggers once per game and forever loop
once per game?
as in once per start of a session or once per start of the main game loop
uh whats the difference
like once per night attempt vs once per game?
@foggy arch
once per starting of the game (the program) and once per starting of the session
if you want it to start when the script is loaded use Awake()