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 trialReginald Augustin
2,722 PointsAdd a start and an end
my script doesn't work , i used the using unity engine.scenemangement and i also used the sceneManger.loadScene method but my script is still generation an error.
using UnityEngine; using System.Collections; 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 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);
}
2 Answers
Reginald Augustin
2,722 PointsThe script i pasted above i am only seeing error in when i compile it says
birdMovement.enabled = false; (unexpected symbol birdMovement)
Seth Kroger
56,413 PointsThe line above the error is missing a semi-colon. Unexpected symbol errors are usually cause by a mistake further up in the code like this.