Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Hassan Wattar
Hassan Wattar
1,166 Points

game starts without me even pressing spacebar and frog dosent move

i checked all my code i dont see anything wrong here is my code

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>();

    playerMovement.enabled = false;
    birdMovement.enabled = false;
    followCamera.enabled = false;

// Update is called once per frame
void Update ()
    if (gameStarted == false && Input.GetKeyUp (KeyCode.Space))
    if (playerHealth.alive == false)

        restartTimer = restartTimer + Time.deltaTime;

        if(restartTimer >= restartDelay)
private void StartGame ()   
    //set the game state
    gameStarted = true;

    // remove start text
    gameStateText.color = Color.clear;

    //allow player to move
    playerMovement.enabled = true;

    //allow bird to move
    birdMovement.enabled = true;

    //allow camera to move 
    followCamera.enabled = true;

private void EndGame ()
    // set the game state
    gameStarted = false;

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

    // remove player from game


pls help

1 Answer

10,908 Points

Maybe if you press the space button it will then allow you to move.

Hope this helps.