using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class PathManager : MonoBehaviour {
public Transform prefab;
public int numberofObjects;
public float recycleOffset;
public Vector3 startPosition;
public Vector3 minGap,maxGap;
private Vector3 nextPosition;
private Queue<Transform> objectQueue;
// Use this for initialization
void Start () {
GameEventManager.GameStart += GameStart;
GameEventManager.GameOver += GameOver;
nextPosition = startPosition;
objectQueue = new Queue<Transform> (numberofObjects);
for (int i = 0; i< numberofObjects; i++) {
objectQueue.Enqueue((Transform)Instantiate(prefab));
}
for (int i = 0; i< numberofObjects; i++) {
Recycle();
}
}
// Update is called once per frame
void FixedUpdate () {
if (objectQueue.Peek ().localPosition.x + recycleOffset < Runner.distance) {
Recycle();
}
}
private void Recycle(){
Vector3 position = nextPosition;
Transform m_object = objectQueue.Dequeue ();
m_object.localPosition = position;
objectQueue.Enqueue (m_object);
nextPosition += new Vector3 (
Random.Range (minGap.x, maxGap.x),
Random.Range (minGap.y, maxGap.y),
Random.Range (minGap.z, maxGap.z));
}
private void GameStart(){
this.transform.localPosition = startPosition;
this.enabled = true;
}
private void GameOver(){
startPosition = new Vector3 (-21f, -7f, 0);
nextPosition = new Vector3 (-21f, -7f, 0);
for (int i = 0; i< numberofObjects; i++) {
Recycle();
}
}
}
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class GameManager : MonoBehaviour {
public Text gameovertext, gamestarttext, touchbuttontext;
// Use this for initialization
void Start () {
gameovertext.enabled = false;
GameEventManager.GameStart += GameStart;
GameEventManager.GameOver += GameOver;
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.Space)) {
GameEventManager.TriggerGameStart();
}
}
private void GameStart(){
gameovertext.enabled = false;
gamestarttext.enabled = false;
touchbuttontext.enabled = false;
enabled = false;
}
private void GameOver(){
gameovertext.enabled = true;
touchbuttontext.enabled = true;
enabled = true;
}
}
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class ScoreManager : MonoBehaviour {
public static float Gamescore;
public Text text;
// Use this for initialization
void Start () {
Gamescore = 0;
}
// Update is called once per frame
void Update () {
text.text = "Score : " + Gamescore;
Gamescore += Time.smoothDeltaTime;
}
}