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 trialAngus Eliott
3,793 PointsC# Script error
what is wrong with this code? (I wrote it exactly as Nick wrote it )
using UnityEngine;
using UnityEngine.UI;
public class GameState : MonoBehaviour {
private bool gameStarted = false;
[SerializeField]
private Text gameStateText;
[SerializeField]
private GameObject player;
[SerializeField]
private BirdMovement birdMovment;
[SerializeField]
private FollowCamera followCamera;
private float restartDelay = 3;
private float restartTimer;
private PlayerMovement playerMovment;
private PlayerHealth playerHealth;
private PlayerMovement playerMovement;
// 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
playerMovment.enabled = false;
// Prevent the bird from moving at the start of the game
birdMovment.enabled = false;
// Prevent the Camera from moving to its game position
followCamera.enabled = false;
}
// Update is called once per frame
void Update () {
// If the Game has not started And the player has pressed the space bar...
if (gameStarted == false && Input.GetKeyUp (KeyCode.Space))
{
StartGame();
}
// if the player is not alive...
if (playerHealth.alive == false)
{
// end the game...
EndGame();
// incrament a timer to count up to restarting...
restartTimer = restartTimer + Time.deltaTime;
// and if it reaches the restart Delay...
if (restartTimer >= restartDelay)
{
// reload the currently loaded level
Application.LoadLevel (Application.loadedLevel);
}
}
}
private void StartGame
{
GameStarted = true();
// Remove Start Text...
gameStateText.color = Color.clear;
// Allow the player to move...
playerMovement.enabled = true;
// Allow the bird to move...
bridMovement.enabled = true;
// allow the camera to move...
followCamera.enabled = true;
}
private void EndGame
{
GameStarted = false;
// Show the Gameover Text...
gameStateText.enabled = Color.white;
gameStateText.enabled = "Game over!"
// Remove the player from the scene...
player.SetActive (false);
}
}
1 Answer
Josiah Horne
2,085 PointsI might be wrong but you didn't put a semicolon at the end of this code. gameStateText.enabled = "Game over!"