Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class GameHandler : MonoBehaviour {
- public float x = 0;
- public float y = 0;
- public float x1 = 10;
- public float y1 = 10;
- public Transform spawnPoint;
- public GameObject playerToSpawn;
- private GameObject playerClone;
- public Transform cartSpawn;
- public GameObject cartPrefab;
- private GameObject cartClone;
- public bool gameStarted = false;
- public SmoothFollow _smFollow;
- public string introPar = "";
- public bool hookedOn = false;
- public float timeBeforeHooking = 20;
- public float defaultTimeBefHooking = 0;
- private float failTimer = 3;
- public bool gameFail = false;
- public bool gameEnded = false;
- public bool pauseGame = false;
- public float mainTimer = 0;
- private string word1 = "You lasted about: ";
- private string word2 = "Fail, Not even in the Carthole. \n Put your junk in that cart";
- public int wordCode = 0;
- //this is to make game handler a main instance so i can retrieve info out of it
- private static GameHandler instance;
- public static GameHandler Instance()
- {
- return instance;
- }
- void Start()
- {
- instance = this;
- defaultTimeBefHooking = timeBeforeHooking;
- }
- void Update()
- {
- if(gameStarted)
- {
- //game started but now we check if we hooked on or not
- if(!hookedOn)
- {
- timeBeforeHooking -= Time.deltaTime;
- if(timeBeforeHooking <= 0)
- {
- wordCode = 2;
- pauseGame = true;
- gameFail = true;
- }
- }
- else
- {
- mainTimer += Time.deltaTime;
- }
- if(gameEnded)
- {
- wordCode = 1;
- pauseGame = true;
- }
- }
- if(pauseGame)
- {
- Time.timeScale = 0;
- }
- else
- {
- Time.timeScale = 1;
- }
- if(playerClone)
- {
- _smFollow.target = GameObject.FindWithTag("Player").transform;
- }
- }
- void OnGUI()
- {
- Matrix4x4 oldMatrix;
- Matrix4x4 tMatrix;
- int width = 1024;
- int height = 768;
- oldMatrix = GUI.matrix; //store the current matrix
- //construct matrix to scale to actual view size
- tMatrix = Matrix4x4.TRS(Vector3.zero,Quaternion.identity, new Vector3(1.0f * Screen.width/width,1.0f * Screen.height/height, 1.0f));
- GUI.matrix = tMatrix; //set the gui matrix to the scaling matrix
- //draw gui here
- if(!gameStarted)
- {
- GUI.Window(0,new Rect(350,180,350,350),IntroWindow,"");
- }
- if(!hookedOn && !gameFail)
- {
- GUI.Label(new Rect(470,230,200,20),"Time Left: " + timeBeforeHooking.ToString("F1"));
- }
- if(gameFail)
- {
- GUI.Label(new Rect(470,230,200,60),word2 );
- //show a button to restart
- if(GUI.Button(new Rect(430,260,200,40),"Restart"))
- {
- hookedOn = false;
- timeBeforeHooking = defaultTimeBefHooking;
- wordCode = 0;
- Destroy(cartClone);
- Destroy(playerClone);
- gameStarted = false;
- pauseGame = false;
- gameEnded = false;
- gameFail = false;
- }
- }
- if(gameEnded)
- {
- GUI.Label(new Rect(470,230,200,20),word1 + mainTimer.ToString("F1") );
- //show a button to restart
- if(GUI.Button(new Rect(430,260,200,40),"Restart"))
- {
- hookedOn = false;
- timeBeforeHooking = defaultTimeBefHooking;
- wordCode = 0;
- Destroy(cartClone);
- Destroy(playerClone);
- gameStarted = false;
- pauseGame = false;
- gameEnded = false;
- }
- }
- GUI.matrix = oldMatrix; //set original back
- }
- private void IntroWindow(int id)
- {
- GUI.Label(new Rect(100,20,200,20),"How Long Can You Last?");
- introPar = GUI.TextArea(new Rect(20,45,315,155),introPar,200);
- if(GUI.Button(new Rect(70,230,200,40),"Start Game"))
- {
- if(!playerClone)
- {
- //setup player
- playerClone = Instantiate(playerToSpawn,spawnPoint.position,Quaternion.identity) as GameObject;
- //setup cart
- cartClone = Instantiate(cartPrefab,cartSpawn.position,Quaternion.identity) as GameObject;
- gameStarted = true;
- }
- }
- }
- }
- *******************************************************************************************************
- using UnityEngine;
- using System.Collections;
- public class WankSensor : MonoBehaviour {
- //if we connected with the ding dong then we are hooked
- // void OnTriggerEnter(Collider other)
- // {
- // if(other.collider.CompareTag("Wanker"))
- // {
- // GameHandler.Instance().hookedOn = true;
- // Debug.Log("hooked on");
- // }
- // }
- //if we stay we score
- void OnTriggerEnter(Collider other)
- {
- if(other.collider.CompareTag("Wanker"))
- {
- GameHandler.Instance().hookedOn = true;
- //Debug.Log("hooked on");
- }
- }
- //if we stay we score
- void OnTriggerStay(Collider other)
- {
- if(other.collider.CompareTag("Wanker"))
- {
- GameHandler.Instance().hookedOn = true;
- //Debug.Log("hooked on");
- }
- }
- //if we exit we failed
- void OnTriggerExit(Collider other)
- {
- if(other.collider.CompareTag("Wanker"))
- {
- GameHandler.Instance().gameEnded = true;
- //Debug.Log("we lost");
- }
- }
- }
- ********************************************************************************************
- using UnityEngine;
- using System.Collections;
- public class SimpleCar : MonoBehaviour {
- public float moveSpeed = 60;
- // Update is called once per frame
- void FixedUpdate ()
- {
- float h = Input.GetAxis("Horizontal");
- rigidbody.AddRelativeForce(Vector3.forward * moveSpeed * h,ForceMode.Impulse);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment