Advertisement
fishamatician

Player controller

Jan 28th, 2015
373
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PlayerControler : MonoBehaviour
  5. {
  6.     public float speed;
  7.     public GUIText countText;
  8.     public GUIText WinText;
  9.     private int count;
  10.     private int cur_Level;
  11.     private int Level_cap;
  12.     public AudioClip Pickup_S;
  13.     public AudioClip Win_S;
  14.     public Vector3 lastGoodPosition;
  15.     public Vector3 gravity;
  16.  
  17.  
  18.  
  19.  
  20.     void Start ()
  21.     {
  22.         count = 0;
  23.         cur_Level = 0;
  24.         Level_cap = 4;
  25.         SetCountText ();
  26.         WinText.text = "";
  27.         Physics.gravity = gravity;
  28.     }
  29.  
  30.  
  31.  
  32.     void FixedUpdate()
  33.     {
  34.         float moveHorizontal = Input.GetAxis("Horizontal");
  35.         float moveVertical = Input.GetAxis("Vertical");
  36.  
  37.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
  38.  
  39.         rigidbody.AddForce(movement * speed * Time.deltaTime);
  40.  
  41.         //if (gameObject.tag == "Player")
  42.         //{
  43.     //      Application.LoadLevel (Application.loadedLevel);
  44. //      }
  45.  
  46.     }
  47.  
  48.     void OnTriggerEnter(Collider other)
  49.     {
  50.         if (other.gameObject.tag == "Pickup")
  51.         {
  52.             audio.PlayOneShot(Pickup_S, 0.7F);
  53.             other.gameObject.SetActive(false);
  54.             count = count + 1;
  55.             SetCountText();                    
  56.            
  57.         }
  58.  
  59.        
  60.        
  61.     }
  62.  
  63.  
  64.    
  65.     void OnCollisionEnter(Collision collision)
  66.     {
  67.         if (collision.collider.tag == "Player")
  68.         {
  69.             lastGoodPosition = transform.position;
  70.         }
  71.         else if (collision.collider.tag == "PlaneofDeath")
  72.         {
  73.             transform.position = lastGoodPosition;
  74.         }
  75.     }
  76.  
  77.    
  78.     void SetCountText()
  79.     {
  80.         countText.text = "Count: " + count.ToString();
  81.         if (count >= 20)
  82.         {
  83.             WinText.text = "You WIN!";
  84.             audio.PlayOneShot(Win_S, 0.7F);
  85.             Level_cap = cur_Level +1;
  86.  
  87.  
  88.  
  89.             StartCoroutine(NextLevel());
  90.            
  91.            
  92.         }
  93.     }
  94.    
  95.     IEnumerator NextLevel()
  96.     {
  97.         yield return new WaitForSeconds(3);
  98.         int i = Application.loadedLevel;
  99.         //Application.LoadLevel(i + 1);
  100.        
  101.         if (i<=Level_cap)
  102.         {
  103.             Application.LoadLevel(i + 1);
  104.            
  105.         }
  106.         else if (i>Level_cap)
  107.         {
  108.             Application.LoadLevel(0);
  109.         }
  110.        
  111.     }
  112.  
  113.  
  114.  
  115.  
  116. }
Advertisement
RAW Paste Data Copied
Advertisement