Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
73
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4.  
  5. public class PlayerController : MonoBehaviour {
  6.  
  7.     public float speed;
  8.     public Text countText;
  9.     public Text winText;
  10.  
  11.  
  12.     //private Rigidbody rb;
  13.     private int count;
  14.     public GameObject[] pickups;
  15.     public Image panel;
  16.  
  17.     public AudioClip PickupSound;
  18.     public AudioClip WinSound;
  19.  
  20.     private AudioSource _aSrc;
  21.  
  22.     private bool hasPlayed = false;
  23.  
  24.  
  25.     public void Awake()
  26.     {
  27.         pickups = GameObject.FindGameObjectsWithTag("Pickup");
  28.     }
  29.  
  30.     void Start ()
  31.     {
  32.         //rb = GetComponent<Rigidbody>();
  33.         _aSrc = GetComponent<AudioSource>();
  34.  
  35.         count = 0;
  36.         winText.text = "";
  37.     }
  38.  
  39.     void FixedUpdate()
  40.     {
  41.         SetCountText();
  42.     }
  43.  
  44.     void OnTriggerEnter(Collider other)
  45.     {
  46.         if (other.gameObject.CompareTag ("Pickup"))
  47.         {
  48.             AudioSource.PlayClipAtPoint (PickupSound, transform.position);
  49.             other.gameObject.SetActive (false);
  50.             count++;
  51.         }
  52.     }
  53.  
  54.     void SetCountText()
  55.     {
  56.         countText.text = "BLOX: " + count.ToString ();
  57.  
  58.         if (count >= pickups.Length)
  59.         {
  60.             if(!hasPlayed)
  61.             {
  62.                 PlayWinSound();
  63.             }
  64.  
  65.  
  66.             winText.text = "WINNER WINNER CHICKEN DINNER";
  67.             panel.enabled = true;
  68.             //Destroy (winText, 1.0f);
  69.             //Destroy(panel, 1.0f);
  70.             Invoke("PanelOff", 1.0f);
  71.         }
  72.     }
  73.  
  74.     public void PanelOff()
  75.     {
  76.         panel.gameObject.SetActive (false);
  77.     }
  78.  
  79.     public void PlayWinSound()
  80.     {
  81.         _aSrc.PlayOneShot(WinSound);
  82.         hasPlayed = true;
  83.     }
  84.  
  85. }
Advertisement
RAW Paste Data Copied
Advertisement