HI I am in a bad problem . i have a code but Unity gives me this Error : Cannot implicitly convert type void' to bool’. and here is my code :
[89725-code.png|89725]
please help .
Thanks a lot
HI I am in a bad problem . i have a code but Unity gives me this Error : Cannot implicitly convert type void' to bool’. and here is my code :
[89725-code.png|89725]
please help .
Thanks a lot
The error message, I assume, relates to line 8. If you look at the docs for Application.LoadLevel, you’ll see that it does not return any value to its caller (it is “void”). The condition supplied to an “if” statement, however, needs to be true/false (a “bool”).
That’s what the error is telling you - you can’t use Application.LoadLevel as a condition to an if statement because you cannot evaluate a void as a bool.
Your Problem is in Line 8, as LoadLevel return type is void and unity returns Error : “Cannot implicitly convert type void to bool” as it expects a boolean i.e if ( bool ) { … }
I guess you wanted to use Application.loadedLevelName
if (Application.loadedLevelName == "game")
{
// do stuff
}
Though, you can’t do it that way, loading takes a little bit of time, you’ll need to wait for it to complete.
Have a look at coroutines and SceneManagement.