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

a lot of error

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement;

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 playerMovement to move
    playerMovement.enabled = false;

    //prevent the birdMovement to move
    birdMovement.enabled = false;

    //prevent the followCamera to move
    followCamera.enabled = false;

}

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

    //if the game is not started and the player preses the spacebar then...
    if (gameStarted == false && Input.GetKeyUp(KeyCode.Space)

    //...start the game
    {
        StartGame();
    }


    //if the player is not alive...
    if (playerHealth.alive == false)
    //...end the game
    {
        EndGame();

        //...increment the timer to count up to restarting
        restartTimer = restartTimer + Time.deltaTime;

        //...and if it reaches the restart delay...
        if (restartTimer >= restartDelay)
        {
            //...then reload the currently loaded scene
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
        }
    }
}

private void StartGame()
{
    //set the game state
    gameStarted = true;

    //set the text color into invisible
    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 ()
{
    gameStarted = false;

    //show the text game over
    gameStateText.color = Color.white;
    gameStateText.text = "Game Over!";

    //remove the player from the game
    player.SetActive(false);
}

}

when i completed the code and save the scripts and the scene,it's fine at all but 1 day after,error starts to coming out such as: Assets/Scripts/GameState.cs(47,8): error CS1525: Unexpected symbol '{' Assets/Scripts/GameState.cs(47,8): error CS1525: Unexpected symbol 'if' in class,struct, or interface member declaration Assets/Scripts/GameState.cs(47,8): error CS1525: Unexpected symbol '==' in class,struct, or interface member declaration Assets/Scripts/GameState.cs(47,8): error CS1525: Primary construct body is not allowed Assets/Scripts/GameState.cs(47,8): error CS1525: Unexpected symbol 'void', expecting 'class', 'delegate', 'enum', 'interface', 'partial', or 'struct'

please help me as soon as possible