There was such question: I need that if my character moves that there was an animation and a sound. The problem is that I don’t understand how to put the function in “if”. Thank you all in advance!
The function is void, so you will not get a return value. You would need to return a bool value or great logic behind the function call. Void does not return anything so no logic can be made.
Thats not how you use an if statement.
if(some condition which resolves to a bool i.e. true or false)
{
// some code that you want to execute if the condition is true
}
To put something in the parameters of an if statement it needs to be equivalent to a bool. So either a bool literal i.e. true or false, a conditional statement i.e. someVar >= anotherVar or a method or function that returns a bool i.e.
private bool IsGreaterOrEqualToTen(int value)
{
return value >= 10;
}
if(IsGreaterOrEqualToTen(12))
{
// Do this if true
}