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

Game error

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 moving at the start of the game
        playerMovement.enabled = false;
        // prevent the bird from moving at the start of the game
        birdMovement.enabled = false;
        // prevent the follow camera from moving game position
        followCamera.enabled = false;
    }

    // Update is called once per frame
    void Update () {
        if (gameStarted == false && Input.GetKeyUp (KeyCode.Space) || Input.GetKeyUp (KeyCode.Return) || Input.GetKeyUp (KeyCode.UpArrow)) {
            StartGame();
        }
        // if the player is no longer alive end game
        if (playerHealth.alive == false) {
            EndGame();

            //timer count up to restarting
            restartTimer = restartTimer + Time.deltaTime;
            // and if it reaches the restart delay..
            if (restartTimer >= restartDelay) {
                // ... then reload the currently loaded level
                Application.LoadLevel (Application.loadedLevel);
            }
        }
        if (Input.GetKey(KeyCode.Escape))
        {
            Application.Quit();
        }
    }
    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;
        birdMovement.enabled = true;
        followCamera.enabled = true;
    }
    private void EndGame() {
        gameStarted = false;
        // show the game over text
        gameStateText.color = Color.white;
        gameStateText.text = "You Lose!";
        // remove the player
        player.SetActive (false);
    }
}

That's my code.

So I follow the steps and after awhile I finished and I got an error.

Can someone help?

1 Answer

Harry James
Harry James
14,780 Points

Hey Channon!

Go take a look at Alejandro Chiari's answer on the Community over here

This should fix your problem for you (Go to Window >> Lighting >> Lightmaps >> Untick the Auto Checkbox >> Press Build).

If his answer helped you then be sure to give him a +1 on his forum post :)

thanks but that did not work.But I did fix my problem now AND because of you and alejandro chiari's answer

I fixed a weird problem with the Lighting.Thanks Harry

Cheers, Channon hall