I have just started with unity, and have never used C# before. The code below raises the error The name 'direction' does not exist in the current context
and I have no clue why. I'm sure it's super obvious but I am new to all this.
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
if (moveVertical != 0 || moveHorizontal != 0) {
if (moveVertical > 0) {
string direction = "up";
} else if (moveVertical < 0) {
string direction = "down";
} else if (moveHorizontal > 0) {
string direction = "right";
} else if (moveHorizontal < 0) {
string direction = "left";
} else {
string direction = "###";
}
Debug.Log(direction);
}