Upload
hendra-riswan
View
214
Download
0
Embed Size (px)
Citation preview
7/25/2019 script player movement
1/2
using UnityEngine;using UnityEngine.UI;using System.Collections;
public class GameManager : MonoBehaviour {
public Camera cam;public GameObject[] randomObject;public float timeLeft;public Text Timertext;public GameObject gameOverText;public GameObject restartButton;public GameObject splashScreen;public GameObject startButton;
private float maxWidth;private bool playing;
public GUIText scoreText;public int score;
public Vector3[]positions;
// Use this for initializationvoid Start () {if (cam == null){
cam = Camera.main;}playing = false;int randomNumber = Random.Range (0, positions.Length);transform.position = positions [randomNumber];
score = 0;UpdateScore() ;
}
void FixedUpdate () {if (playing){timeLeft -= Time.deltaTime;if (timeLeft < 0) {
timeLeft = 0;}
}}
public void StartGame () {splashScreen.SetActive (false);startButton.SetActive (false);StartCoroutine (Spawn ());
}
IEnumerator restart(){yield return new WaitForSeconds (2.0f);
playing = true;while (timeLeft> 0){
yield return new WaitForSeconds (Random.Range (1.0f, 2.0f));
}
7/25/2019 script player movement
2/2
yield return new WaitForSeconds (2.0f);gameOverText.SetActive (true);yield return new WaitForSeconds (2.0f);restartButton.SetActive (true);
}public void AddScore (int newScoreValue){
score += newScoreValue;UpdateScore ();
}void UpdateScore ()
{scoreText.text = "Score: " + score;
}}