Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Game Development How to Make a Video Game Score, Enemies, and Game State Add a Start and End

Unexpected Symbol birdMovement

After Writing the code of Game State ,i Cant Compile it Because it shows error in 32nd line that birMovement is unexpected error,,the 32nd line in the video

birdMovement.enabled = false;

also while typing the 63rd line in the line Application.LoadLevel (Application.loadedLevel);

I can type itmbut in he list they both are cut out

5 Answers

Never Mind , I just Erased the Lines And Wrote the m Again, Fixed!

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

This is going to be very hard to debug without seeing your code. There's a "Markdown Cheatsheet" link at the bottom of this page :arrow_heading_down: under "Add an answer". This will show you how to post your code so that we can better assist you.

But the "unexpected" error generally indicates that something above that line wasn't closed off properly. I'd look up a line or two and make sure that all open parentheses and closed parentheses match. Hope you find it! :sparkles: If not, come back here and post your code so we can take a look :smiley:

using UnityEngine; using System.Collections; using UnityEngine.UI;

public class GameState : MonoBehaviour {

private bool gameStarted = false;
[SerializeField]
private Text gameStateText;
[SerializeField]
private GameObject player;
[SerializeField]
private BirdMovement birdmovement;
[SerializeField]
private FollowCamera followCamera;
private float restartDelay = 3f;
private float restartTimer;
private PlayerMovement playerMovement;
private PlayerHealth playerHealth;

// Use this for initialization
void Start () {
    Cursor.visible = false;

    playerMovement = player.GetComponent<PlayerMovement> ();
    playerHealth = player.GetComponent<PlayerHealth> ();

    // Prevent The Player From movving at the start of the game
    playerMovement.enabled = false

        // prevent the bird frrom moving at the start of the game
        birdMovement.enabled = false;

    // prevent the follow camera from moving to its game position
    followCamera.enabled = false;

    }

// Update is called once per frame
void Update () {

    // if the gamme is not started and the player presse the space bar...   
    if (gameStarted == false && Input.GetKeyUp (KeyCode.Space)) {

        // ...Start the Game
        StartGame ();

    }

    // if the player is no longer alive...
    if (playerHealth.alive == false) {

        // ...end the game...
        EndGame ();

        // ...increment a timer to count up to restaring...
        restartTimer = restartTimer + Time.deltaTime;

        // ...and if it reaches the restart delay...
        if (restartTimer >= restartDelay) {

            // ...then reload the currently loaded level...
            Application.LoadLevel (Application.loadedLevel);

        }

    }

}

private void StartGame() {

    // Set the game state
    gameStarted = true;

    // Remove the start text
    GameStateText.Color = Color.clear;

    // Allow the player to move
    playerMovement.enabled = true;

    // Allow the bird to move
    birdMovement.enabled = true;

    // Allow the camera to move
    followCamera.enabled = true;

}

private void EndGame () {

    // Set the game state
    gameStarted = false;

    //Show the Game Over Text
    gameStateText.color = Color.white;
    gameStateText.text = "Game Over";

    //Remove The player From the Game
    player.SetActive (false);
}

}

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You've declared this:

[SerializeField]
private BirdMovement birdmovement;

But then you try to access it with this line:

// Allow the bird to move
    birdMovement.enabled = true;

Note the difference in capitalization of birdmovement vs birdMovement. My suggestion is to change the declaration to this:

[SerializeField]
private BirdMovement birdMovement;

Hope this helps! :sparkles:

i have changed it Still it says Assets/Scripts/GameState.cs(32,36): error CS1525: Unexpected symbol `birdMovement'

after changing

using UnityEngine; using System.Collections; using UnityEngine.UI;

public class GameState : MonoBehaviour {

private bool gameStarted = false;
[SerializeField]
private Text gameStateText;
[SerializeField]
private GameObject player;
[SerializeField]
private BirdMovement birdMovement;
[SerializeField]
private FollowCamera followCamera;
private float restartDelay = 3f;
private float restartTimer;
private PlayerMovement playerMovement;
private PlayerHealth playerHealth;

// Use this for initialization
void Start () {
    Cursor.visible = false;

    playerMovement = player.GetComponent<PlayerMovement> ();
    playerHealth = player.GetComponent<PlayerHealth> ();

    // Prevent The Player From movving at the start of the game
    playerMovement.enabled = false

        // prevent the bird frrom moving at the start of the game
        birdMovement.enabled = false;

    // prevent the follow camera from moving to its game position
    followCamera.enabled = false;

    }

// Update is called once per frame
void Update () {

    // if the gamme is not started and the player presse the space bar...   
    if (gameStarted == false && Input.GetKeyUp (KeyCode.Space)) {

        // ...Start the Game
        StartGame ();

    }

    // if the player is no longer alive...
    if (playerHealth.alive == false) {

        // ...end the game...
        EndGame ();

        // ...increment a timer to count up to restaring...
        restartTimer = restartTimer + Time.deltaTime;

        // ...and if it reaches the restart delay...
        if (restartTimer >= restartDelay) {

            // ...then reload the currently loaded level...
            Application.LoadLevel (Application.loadedLevel);

        }

    }

}

private void StartGame() {

    // Set the game state
    gameStarted = true;

    // Remove the start text
    GameStateText.Color = Color.clear;

    // Allow the player to move
    playerMovement.enabled = true;

    // Allow the bird to move
    birdMovement.enabled = true;

    // Allow the camera to move
    followCamera.enabled = true;

}

private void EndGame () {

    // Set the game state
    gameStarted = false;

    //Show the Game Over Text
    gameStateText.color = Color.white;
    gameStateText.text = "Game Over";

    //Remove The player From the Game
    player.SetActive (false);
}

}

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

The line above is missing a semicolon :smiley:

playerMovement.enabled = false

This should be:

playerMovement.enabled = false;

Hope this fixes it! :sparkles:

thanks that is solved ,but now it shows this Assets/Scripts/GameState.cs(77,31): error CS1061: Type UnityEngine.UI.Text' does not contain a definition forColor' and no extension method Color' of typeUnityEngine.UI.Text' could be found (are you missing a using directive or an assembly reference?)

Dont Know Why The Problems are not being shown at once,but one by one

using UnityEngine; using System.Collections; using UnityEngine.UI;

public class GameState : MonoBehaviour {

private bool gameStarted = false;
[SerializeField]
private Text gameStateText;
[SerializeField]
private GameObject player;
[SerializeField]
private BirdMovement birdMovement;
[SerializeField]
private FollowCamera followCamera;
private float restartDelay = 3f;
private float restartTimer;
private PlayerMovement playerMovement;
private PlayerHealth playerHealth;

// Use this for initialization
void Start () {
    Cursor.visible = false;

    playerMovement = player.GetComponent<PlayerMovement> ();
    playerHealth = player.GetComponent<PlayerHealth> ();

    // Prevent The Player From movving at the start of the game
    playerMovement.enabled = false;

        // prevent the bird frrom moving at the start of the game
        birdMovement.enabled = false;

    // prevent the follow camera from moving to its game position
    followCamera.enabled = false;

    }

// Update is called once per frame
void Update () {

    // if the gamme is not started and the player presse the space bar...   
    if (gameStarted == false && Input.GetKeyUp (KeyCode.Space)) {

        // ...Start the Game
        StartGame ();

    }

    // if the player is no longer alive...
    if (playerHealth.alive == false) {

        // ...end the game...
        EndGame ();

        // ...increment a timer to count up to restaring...
        restartTimer = restartTimer + Time.deltaTime;

        // ...and if it reaches the restart delay...
        if (restartTimer >= restartDelay) {

            // ...then reload the currently loaded level...
            Application.LoadLevel (Application.loadedLevel);

        }

    }

}

private void StartGame() {

    // Set the game state
    gameStarted = true;

    // Remove the start text
    gameStateText.Color = Color.clear;

    // Allow the player to move
    playerMovement.enabled = true;

    // Allow the bird to move
    birdMovement.enabled = true;

    // Allow the camera to move
    followCamera.enabled = true;

}

private void EndGame () {

    // Set the game state
    gameStarted = false;

    //Show the Game Over Text
    gameStateText.color = Color.clear;
    gameStateText.text = "Game Over";

    //Remove The player From the Game
    player.SetActive (false);
}

}

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

This one, I really don't know. Because if I copy/paste that code into MonoDevelop it shows no errors and no warnings.

So what Should i do about this unity engine.ui problem