Guest User

scripts, how long can you last

a guest
Apr 27th, 2013
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.58 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class GameHandler : MonoBehaviour {
  5.  
  6.     public float x = 0;
  7.     public float y = 0;
  8.     public float x1 = 10;
  9.     public float y1 = 10;
  10.    
  11.     public Transform spawnPoint;
  12.     public GameObject playerToSpawn;
  13.     private GameObject playerClone;
  14.    
  15.    
  16.     public Transform cartSpawn;
  17.     public GameObject cartPrefab;
  18.     private GameObject cartClone;
  19.    
  20.    
  21.     public bool gameStarted = false;
  22.     public SmoothFollow _smFollow;
  23.    
  24.     public string introPar = "";
  25.    
  26.     public bool hookedOn = false;
  27.     public float timeBeforeHooking = 20;
  28.     public float defaultTimeBefHooking = 0;
  29.    
  30.     private float failTimer = 3;
  31.    
  32.     public bool gameFail = false;
  33.     public bool gameEnded = false;
  34.     public bool pauseGame = false;
  35.    
  36.     public float mainTimer = 0;
  37.    
  38.     private string word1 = "You lasted about: ";
  39.     private string word2 = "Fail, Not even in the Carthole. \n Put your junk in that cart";
  40.     public int wordCode = 0;
  41.    
  42.    
  43.    
  44.     //this is to make game handler a main instance so i can retrieve info out of it
  45.     private static GameHandler instance;
  46.     public static GameHandler Instance()
  47.     {
  48.         return instance;
  49.     }
  50.    
  51.     void Start()
  52.     {
  53.         instance = this;
  54.         defaultTimeBefHooking = timeBeforeHooking;
  55.     }
  56.    
  57.    
  58.     void Update()
  59.     {
  60.         if(gameStarted)
  61.         {
  62.            
  63.             //game started but now we check if we hooked on or not
  64.             if(!hookedOn)
  65.             {
  66.                 timeBeforeHooking -= Time.deltaTime;
  67.                
  68.                
  69.                 if(timeBeforeHooking <= 0)
  70.                 {
  71.                     wordCode = 2;
  72.                     pauseGame = true;
  73.                     gameFail = true;
  74.                 }
  75.             }
  76.             else
  77.             {
  78.                
  79.                 mainTimer += Time.deltaTime;
  80.             }
  81.            
  82.            
  83.             if(gameEnded)
  84.             {
  85.                 wordCode = 1;
  86.                 pauseGame = true;
  87.             }
  88.            
  89.            
  90.            
  91.            
  92.         }
  93.        
  94.        
  95.        
  96.         if(pauseGame)
  97.         {
  98.             Time.timeScale = 0;
  99.         }
  100.         else
  101.         {
  102.             Time.timeScale = 1;
  103.         }
  104.        
  105.        
  106.        
  107.         if(playerClone)
  108.         {
  109.             _smFollow.target = GameObject.FindWithTag("Player").transform;
  110.         }
  111.     }
  112.    
  113.    
  114.     void OnGUI()
  115.     {
  116.         Matrix4x4 oldMatrix;
  117.         Matrix4x4 tMatrix;
  118.        
  119.         int width = 1024;
  120.         int height = 768;
  121.        
  122.         oldMatrix = GUI.matrix; //store the current matrix
  123.        
  124.         //construct matrix to scale to actual view size
  125.         tMatrix = Matrix4x4.TRS(Vector3.zero,Quaternion.identity, new Vector3(1.0f * Screen.width/width,1.0f * Screen.height/height, 1.0f));
  126.        
  127.         GUI.matrix = tMatrix; //set the gui matrix to the scaling matrix
  128.        
  129.        
  130.         //draw gui here
  131.         if(!gameStarted)
  132.         {
  133.             GUI.Window(0,new Rect(350,180,350,350),IntroWindow,"");
  134.         }
  135.        
  136.        
  137.        
  138.         if(!hookedOn && !gameFail)
  139.         {
  140.             GUI.Label(new Rect(470,230,200,20),"Time Left: " + timeBeforeHooking.ToString("F1"));
  141.         }
  142.        
  143.         if(gameFail)
  144.         {
  145.             GUI.Label(new Rect(470,230,200,60),word2 );
  146.            
  147.            
  148.            
  149.             //show a button to restart
  150.             if(GUI.Button(new Rect(430,260,200,40),"Restart"))
  151.             {
  152.                 hookedOn = false;
  153.                 timeBeforeHooking = defaultTimeBefHooking;
  154.                
  155.                 wordCode = 0;
  156.                 Destroy(cartClone);
  157.                 Destroy(playerClone);
  158.                 gameStarted = false;
  159.                 pauseGame = false;
  160.                 gameEnded = false;
  161.                 gameFail = false;
  162.                
  163.             }
  164.         }
  165.        
  166.         if(gameEnded)
  167.         {
  168.            
  169.             GUI.Label(new Rect(470,230,200,20),word1 + mainTimer.ToString("F1") );
  170.            
  171.            
  172.            
  173.             //show a button to restart
  174.             if(GUI.Button(new Rect(430,260,200,40),"Restart"))
  175.             {
  176.                 hookedOn = false;
  177.                 timeBeforeHooking = defaultTimeBefHooking;
  178.                
  179.                 wordCode = 0;
  180.                 Destroy(cartClone);
  181.                 Destroy(playerClone);
  182.                 gameStarted = false;
  183.                 pauseGame = false;
  184.                 gameEnded = false;
  185.                
  186.             }
  187.            
  188.            
  189.            
  190.         }
  191.        
  192.        
  193.        
  194.        
  195.        
  196.        
  197.         GUI.matrix = oldMatrix; //set original back
  198.     }
  199.    
  200.    
  201.    
  202.     private void IntroWindow(int id)
  203.     {
  204.         GUI.Label(new Rect(100,20,200,20),"How Long Can You Last?");
  205.         introPar = GUI.TextArea(new Rect(20,45,315,155),introPar,200);
  206.        
  207.        
  208.         if(GUI.Button(new Rect(70,230,200,40),"Start Game"))
  209.         {
  210.             if(!playerClone)
  211.             {
  212.                 //setup player
  213.                 playerClone = Instantiate(playerToSpawn,spawnPoint.position,Quaternion.identity) as GameObject;
  214.                
  215.                 //setup cart
  216.                 cartClone = Instantiate(cartPrefab,cartSpawn.position,Quaternion.identity) as GameObject;
  217.                
  218.                 gameStarted = true;
  219.                
  220.             }
  221.            
  222.         }
  223.        
  224.     }
  225.    
  226. }
  227.  
  228. *******************************************************************************************************
  229.  
  230.  
  231. using UnityEngine;
  232. using System.Collections;
  233.  
  234. public class WankSensor : MonoBehaviour {
  235.  
  236.     //if we connected with the ding dong then we are hooked
  237. //  void OnTriggerEnter(Collider other)
  238. //  {
  239. //      if(other.collider.CompareTag("Wanker"))
  240. //      {
  241. //          GameHandler.Instance().hookedOn = true;
  242. //          Debug.Log("hooked on");
  243. //      }
  244. //  }
  245.    
  246.     //if we stay we score
  247.     void OnTriggerEnter(Collider other)
  248.     {
  249.         if(other.collider.CompareTag("Wanker"))
  250.         {
  251.             GameHandler.Instance().hookedOn = true;
  252.             //Debug.Log("hooked on");
  253.         }
  254.     }
  255.    
  256.    
  257.    
  258.     //if we stay we score
  259.     void OnTriggerStay(Collider other)
  260.     {
  261.         if(other.collider.CompareTag("Wanker"))
  262.         {
  263.             GameHandler.Instance().hookedOn = true;
  264.             //Debug.Log("hooked on");
  265.         }
  266.     }
  267.    
  268.    
  269.    
  270.     //if we exit we failed
  271.     void OnTriggerExit(Collider other)
  272.     {
  273.         if(other.collider.CompareTag("Wanker"))
  274.         {
  275.             GameHandler.Instance().gameEnded = true;
  276.             //Debug.Log("we lost");
  277.         }
  278.     }
  279.    
  280.    
  281.    
  282.    
  283. }
  284.  
  285.  
  286.  
  287. ********************************************************************************************
  288.  
  289.  
  290. using UnityEngine;
  291. using System.Collections;
  292.  
  293. public class SimpleCar : MonoBehaviour {
  294.    
  295.     public float moveSpeed = 60;
  296.  
  297.    
  298.     // Update is called once per frame
  299.     void FixedUpdate ()
  300.     {
  301.         float h = Input.GetAxis("Horizontal");
  302.         rigidbody.AddRelativeForce(Vector3.forward * moveSpeed * h,ForceMode.Impulse);
  303.  
  304.     }
  305. }
Advertisement
Add Comment
Please, Sign In to add comment