When i run this script unity basicly crashes and i dont know why (i cant pres anything or stop the game runing it dosent close the scren) . I dont even now if the code could be simpler becouse im basicly a beginer and just using things that i know alredy . I would be realy grateful if someone could help
#Unity crashing
1 messages · Page 1 of 1 (latest)
[]cb
Use codeblocks to send code in a message!
To make a codeblock, surround your code with ``` (3 backticks. Click here to see where the key is)
To use syntax highlighting, add the file extension of the language you wish to highlight (cs for C#, cpp for C++)
For example:
```cs
Console.WriteLine("Hello World");
```
Produces:
Console.WriteLine("Hello World");
To send lengthy code, paste it into https://paste.myst.rs/ and send the link of the paste into chat.
@coarse kiln
a powerful website for storing and sharing text and code snippets. completely free and open source.
infinite while loop
{
audioSource.Play();
if (Input.GetMouseButtonDown(0))
{
Debug.Log("sucses");
}
else
{
isCoroutineRunning = false;
elapsedTime = 0;
}
}```
no yield return
no execution pauses (even yield return null pauses for a frame)
code like bool == true or bool == false can be written as bool or !bool --They work the same--
@coarse kiln
Whont it end when elapsed time is grater then 3?
it's behind the while
so elapsedTime can't increase
But if i put it in front it wont increase either?
it should be in the while
Input.GetMouseButtonDown() returns true on one frame only too
Ohhh thanks realy much
it's super unreliable for fixed intervals
I didnt know how to do it beter
yield return null pauses for a frame, maybe that
It pauses the hole frame?
it pauses execution (stops running until the next frame)
there exists:
yield return new WaitUntil(() => boolean)
But that dose work with time or are you refrecing something else?
doesn't work with in-loop variables, as it pauses until boolean is true (not if you use out of loop variables, like Time and stuff).
Okkk thanks
what is your script supposed to do btw?
Its suposed to play a sound ant then wait for the player to enter a buton in a certain amount of time and then it just debugs if the key was enterd(i wil do some more stuf in the future but this is wat i want it to do)
audioSource in the loop would play it constantly
Ohh ya il just put a yield return new waitforseconds()
That should work?
shouldn't it be before loop?