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 trialFiras Awad
1,541 PointsBird Keeps Walking
I am sure the birdMovement is set to false in the EndGame function but the bird keeps walking at the same position where was the frog has been picked up from.
Any Suggestions?
1 Answer
Firas Awad
1,541 Pointsusing System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement;
public class GameState : MonoBehaviour {
[SerializeField]
private Text GameStateText;
[SerializeField]
private GameObject player ;
[SerializeField]
private GameObject bird;
[SerializeField]
private GameObject cameraObject;
private bool gameStarted;
private float restartDelay = 3f;
private float restartTimer;
private PlayerMovement playerMovement;
private BirdMovement birdMovement;
private CameraMovement cameraMovement;
private PickupParticels pickupParticels;
// Use this for initialization
void Start () {
Cursor.visible = false;
playerMovement = player.GetComponent<PlayerMovement> ();
birdMovement = bird.GetComponent<BirdMovement> ();
cameraMovement = cameraObject.GetComponent<CameraMovement> ();
pickupParticels = player.GetComponent<PickupParticels> ();
playerMovement.enabled = false;
birdMovement.enabled = false;
cameraMovement.enabled = false;
}
// Update is called once per frame
void Update () {
if (gameStarted == false && Input.GetKeyUp (KeyCode.Space)) {
GameStart ();
}
if (pickupParticels.Alive == false) {
GameEnd ();
restartTimer = restartTimer + Time.deltaTime;
if (restartTimer >= restartDelay) {
SceneManager.LoadScene (SceneManager.GetActiveScene ().buildIndex);
}
}
}
private void GameStart () {
gameStarted = true;
GameStateText.color = Color.clear;
playerMovement.enabled = true;
birdMovement.enabled = true;
cameraMovement.enabled = true;
}
private void GameEnd () {
gameStarted = false;
GameStateText.color = Color.white;
GameStateText.text = "Game Over!";
playerMovement.enabled = false;
birdMovement.enabled = false;
cameraMovement.enabled = false;
player.SetActive (false);
}
}
Sindre Berge
Courses Plus Student 3,109 PointsSindre Berge
Courses Plus Student 3,109 PointsCan you post your gamestate.cs ?