Hi! so I did a search of the forums but I must not be doing the right search criterion I can’t believe I’m the first to have this problem…
I am following the Unity 5 2d essential training on lynda.com and cannot get my game manager to start the game.
using UnityEngine;
using System.Collections;
public class GameManager : MonoBehaviour {
public GameObject playerPrefab;
private bool gameStarted;
private TimeManager timeManager;
private GameObject player;
private GameObject floor;
private Spawner spawner;
void Awake () {
floor = GameObject.Find(“Foreground”);
spawner = GameObject.Find(“Spawner”).GetComponent();
timeManager = GetComponent();
}
void Start()
{
var floorHeight = floor.transform.localScale.y;
var pos = floor.transform.position;
pos.x = 0;
pos.y = -((Screen.height / PixelPerfectCamera.pixelsToUnits)/2 - floorHeight/2);
floor.transform.position = pos;
spawner.active = false;
gameStarted = false;
Time.timeScale = 0;
}
//everything went smoothly until I added this. it’s like it won’t accept the input if the timescale is 0. Thoughts?
void update()
{
if (!gameStarted && Time.timeScale == 0)
{
if (Input.anyKeyDown)
{
timeManager.ManipulateTime(1, 1f);
ResetGame();
}
}
}
void OnPlayerKilled()
{
spawner.active = false;
var playerDestroyScript = player.GetComponent();
playerDestroyScript.DestroyCallback -= OnPlayerKilled;
player.GetComponent().velocity = Vector2.zero;
timeManager.ManipulateTime(0, 5.5f);
gameStarted = false;
}
void ResetGame () {
spawner.active = true;
player = GameObjectUtil.Instantiate(playerPrefab, new Vector3(0, Screen.height / PixelPerfectCamera.pixelsToUnits / 2, 0));
var playerDestroyScript = player.GetComponent();
playerDestroyScript.DestroyCallback += OnPlayerKilled;
gameStarted = true;
}
}