Unity errors

So I made the code as the video said to but it ended up first with this: Assets/NumberWizard.cs(32,13): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
Here is the code I used:

public class NumberWizard : MonoBehaviour {

	// Use this for initialization
	void Start () {
        int max = 1000;
        int min = 1;

        Debug.Log("Welcome to my guessing game.");
        Debug.Log("Think of a number.");
        Debug.Log("The highest number you can choose: " + max);
        Debug.Log("And the lowest number you can choose: " + min);
        Debug.Log("Tell me if your number is higher or lower than 500");
        Debug.Log("Push the Up arrow if it is higher, Down key for lower and Enter if we got it right! :D");
	}
	
	// Update is called once per frame
	void Update () {
        //KeyCode is for picking which button I want to recognize.
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            Debug.Log("Up Arrow key was pressed.");
        }
        else if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            Debug.Log("Down Arrow key was pressed.");
        }
        //Return Key is the Enter Key!!!!
        else(Input.GetKeyDown(KeyCode.Return));
        {
            Debug.Log("Enter key was pressed.");
        }
    }
}

So I decided to change the else to else for the enter key but Unity keeps saying Assets/NumberWizard.cs(33,9): warning CS0642: Possible mistaken empty statement and when I play on the console it keeps constantly hitting the enter key (unless I press the up or down key). I know why it is doing this but I am not sure how to fix either situation (such a noob lol). Any help would be appreciated.

Realized I ended the line. XD Still causing issues with else but now else if works fine.

Hi Katie,

You don’t place a condition with an else, for example;

if(thisExampleIsUseful)
{
    Debug.Log("Yes, thanks");
}
else
{
    Debug.Log("No, not really");
}

By the way, the error message you quoted includes a line number, but because you haven’t posted your full script these become less useful, please post the full script if you are referencing error messages and also apply code fencing characters before/after your copy/pasted code - the easier you make it for people to help you, the more people are likely to help you :slight_smile:

Hope this helps :slight_smile:


See also;

Privacy & Terms