so first this is my first game and I have done essentials so please don’t hate because I already know this is going to seem stupid to some.
Basically I don’t want a timer in my game at all. I only want to get a game-over and then have my restart button show up by missing a single ball and not catching it in my basket.
this is my GameController script.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class GameController : MonoBehaviour {
public Camera cam;
public GameObject ball;
public GameObject gameOverText;
public GameObject restartButton;
public GameObject splashScreen;
public GameObject startButton;
public HatController hatController;
private float maxWidth;
private bool playing;
// Use this for initialization
void Start () {
if (cam == null) {
cam = Camera.main;
}
playing = false;
Vector3 upperCorner = new Vector3 (Screen.width, Screen.height, 0.0f);
Vector3 targetWidth = cam.ScreenToWorldPoint (upperCorner);
float ballWidth = ball.renderer.bounds.extents.x;
maxWidth = targetWidth.x;
}
void FixedUpdate () {
}
public void StartGame () {
splashScreen.SetActive (false);
startButton.SetActive (false);
hatController.ToggleControl (true);
StartCoroutine (Spawn ());
}
IEnumerator Spawn () {
yield return new WaitForSeconds (2.0f);
playing = true;
while (true) {
Vector3 spawnPosition = new Vector3 (
Random.Range (-maxWidth, maxWidth),
transform.position.y,
0.0f
);
Quaternion spawnRotation = Quaternion.identity;
Instantiate (ball, spawnPosition, spawnRotation);
yield return new WaitForSeconds (Random.Range (1.0f, 2.0f));
}
yield return new WaitForSeconds (2.0f);
gameOverText.SetActive (true);
yield return new WaitForSeconds (2.0f);
restartButton.SetActive (true);
}
}
this is my score script.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Score : MonoBehaviour {
public Text scoreText;
public int ballValue;
private int score;
// Use this for initialization
void Start () {
score = 0;
UpdateScore ();
}
void OnTriggerEnter2D () {
score += ballValue;
UpdateScore ();
}
void UpdateScore () {
scoreText.text = “Coins Collected:\n” + score;
}
}
my basket controller script
using UnityEngine;
using System.Collections;
public class HatController : MonoBehaviour {
public Camera cam;
private float maxWidth;
private bool canControl;
// Use this for initialization
void Start () {
if (cam == null) {
cam = Camera.main;
}
canControl = false;
Vector3 upperCorner = new Vector3 (Screen.width, Screen.height, 0.0f);
Vector3 targetWidth = cam.ScreenToWorldPoint (upperCorner);
maxWidth = targetWidth.x;
}
// Update is called once per frame
void Update () {
if (canControl) {
Vector3 rawPosition = cam.ScreenToWorldPoint (Input.mousePosition);
Vector3 targetPosition = new Vector3 (rawPosition.x , 0.0f, 0.0f);
float targetWidth = Mathf.Clamp (targetPosition.x, -maxWidth, maxWidth);
targetPosition = new Vector3 (targetWidth, targetPosition.y, targetPosition.z);
rigidbody2D.MovePosition (targetPosition);
}
}
public void ToggleControl (bool toggle) {
canControl = toggle;
}
}
My Destroy object script
using UnityEngine;
using System.Collections;
public class DestroyObject : MonoBehaviour {
void OnTriggerEnter2D (Collider2D other) {
Destroy (other.gameObject);
}
}
and finally my restart button script.
using UnityEngine;
using System.Collections;
public class Restart : MonoBehaviour {
public void RestartGame () {
Application.LoadLevel (Application.loadedLevel);
}
}
Please please pleaseeeeee help me out.