I know this might be a silly question, with an easy answer, but after an hour of searching the internet I could not find a way to do this;
public bool GetCollision(int x, int y)
{
bool isPassable;
if (x < 0 || x >= 20)
{
isPassable = false;
}
if (y < 0 || y >= 20)
{
isPassable = true;
}
return isPassable;
}
On the second-to-last line it says that isPassable is unassigned… yet clearly I assign to it in the if statements. There must be some fundamental misunderstanding of “if” statements on my part.
So, how can I do this? Thank you very much.
That is because it doesn’t have a default value set explicitly. Set isPassable to False by default and you’re done.
Also you can do something like this:
EDIT: The above solution would only work if an AND relationship would exist between your IFs.