i would like to know how to add wait time in a function without having to freeze the entire script, is there a surefire method for this, also, would it work in an “if loop” ?
also i would love to know here some of you other people learned unity because youtube is kind of leading me in all different dirrections
also, on a side note, can you make holes in shapes with negative space in unity, or do i have to create a custom shape in blender with a hole in it?
BoxTurtle_Games:
i would like to know how to add wait time in a function without having to freeze the entire script, is there a surefire method for this, also, would it work in an “if loop” ?
Look up Coroutines.
BoxTurtle_Games:
also, on a side note, can you make holes in shapes with negative space in unity, or do i have to create a custom shape in blender with a hole in it?
Yes but boolean mesh operations are an advanced things to be working with. If you don’t need it in runtime, make it in Blender.
i found that this works better from one of my old scripts, but thanks for the help
Invoke(“p”,num);
//p is a function, num is a float
You should still learn Coroutines.
2 Likes
[...]
StartCoroutine(MyDelayedFunc(1f));
[...]
private IEnumerator MyDelayedFunc(float timeToWait)
{
yield return new WaitForSeconds(timeToWait);
// Your code here.
[...]
}
Alternatively, if you’d rather use callback:
private static void Wait(float timeToWait, System.Action callback)
{
StartCoroutine(WaitCoroutine(timeToWait, callback));
}
private static IEnumerator WaitCoroutine(float timeToWait, System.Action callback)
{
yield return new WaitForSeconds(timeToWait);
callback.Invoke();
}
Then you could just do:
Wait(1f, () =>
{
// Your code here.
[...]
});