Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.26 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4.  
  5. public class PlayerController : MonoBehaviour
  6. {
  7.     private Rigidbody rb;
  8.     public float speed;
  9.     private int score;
  10.     public Text scoreText;
  11.     public Text winText;
  12.     public int amount_of_hits=0;
  13.     public int needed_hits=2;
  14.     bool coll=false;
  15.     public float small_time = 10.0f;
  16.     bool small=false;
  17.     bool fun = false;
  18.     bool hammer = false;
  19.  
  20.  
  21.  
  22.     void Start ()
  23.     {
  24.         rb = GetComponent<Rigidbody> ();
  25.         score = 0;
  26.         SetScoreText ();
  27.         winText.text = "";
  28.     }
  29.  
  30.  
  31.     void Update ()
  32.     {
  33.  
  34.         if (small == true)
  35.         {
  36.             small_time -= Time.deltaTime;
  37.             if (small_time <= 0)
  38.             {
  39.                 small = false;
  40.                 small_time = 10.0f;
  41.                 transform.localScale += new Vector3 (0.7F, 0.7F, 0.7F);
  42.                 transform.position = new Vector3 (GameObject.FindGameObjectWithTag ("Player").transform.position.x, 0.50f, GameObject.FindGameObjectWithTag ("Player").transform.position.z);
  43.             }
  44.         }
  45.     }
  46.  
  47.     void FixedUpdate ()
  48.     {
  49.         float moveHorizontal = Input.GetAxis ("Horizontal");
  50.         float moveVertial = Input.GetAxis ("Vertical");
  51.         //testowe sterowanie na komputer
  52.         if (fun == false) {
  53.             Vector3 movement = new Vector3 (moveHorizontal, 0, moveVertial);
  54.             rb.AddForce (movement * speed);
  55.         } else {
  56.             Vector3 movement = new Vector3 (-moveHorizontal, 0, -moveVertial);
  57.             rb.AddForce (movement * speed);
  58.         }
  59.         //sterowanie na telefon
  60.         //float moveHorizontal = Input.acceleration.x;
  61.         //float moveVertical = Input.acceleration.z;
  62.         //Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
  63.         //rb.AddForce(movement * speed * Time.deltaTime);
  64.  
  65.  
  66.     }
  67.  
  68.     void OnTriggerEnter(Collider other)
  69.     {
  70.         //podnoszenie rzeczy
  71.         if (other.gameObject.CompareTag ("Pickup")) {
  72.             other.gameObject.SetActive (false);
  73.             score++;
  74.         }
  75.         if ((score >= 8) || (other.gameObject.CompareTag("Meta"))){
  76.             winText.text = "WYGRAŁEŚ!";
  77.             Time.timeScale = 0;
  78.                 SetScoreText ();
  79.             }
  80.  
  81.         //zmiana rozmiaru
  82.         if(other.gameObject.CompareTag("Size"))
  83.         {
  84.             other.gameObject.SetActive(false);
  85.             transform.localScale -= new Vector3(0.7F, 0.7F, 0.7F); //zmniejsza kulkę o podany vector
  86.             transform.position = new Vector3(GameObject.FindGameObjectWithTag("Player").transform.position.x, 0.15f, GameObject.FindGameObjectWithTag("Player").transform.position.z); //bez tego kulka lata po pomniejszeniu nad ziemią
  87.             small=true;
  88.         }
  89.  
  90.         //pickupy kolorowe
  91.         if (other.gameObject.CompareTag ("hammer"))
  92.         {
  93.             other.gameObject.SetActive (false);
  94.             hammer = true;
  95.         }
  96.  
  97.         //zmiana osi sterowania
  98.         if (other.gameObject.CompareTag ("axes")) {
  99.             other.gameObject.SetActive (false);
  100.             fun=true;
  101.         }
  102.     }
  103.  
  104.     void OnCollisionEnter(Collision ot)
  105.     {
  106.         //rozbijanie ścian
  107.         if (ot.gameObject.CompareTag("Destroyable"))
  108.         {
  109.             if (coll == false && amount_of_hits >= needed_hits)
  110.             {
  111.                 coll = true;
  112.                 ot.gameObject.SetActive(false);
  113.             }
  114.             else
  115.             {
  116.                 coll = true;
  117.                 amount_of_hits++;
  118.             }
  119.  
  120.         }
  121.         if (ot.gameObject.CompareTag ("mur")) {
  122.             if (hammer == true)
  123.                 ot.gameObject.SetActive(false);
  124.         }
  125.  
  126.     }
  127.  
  128.     void OnCollisionExit(Collision ot)
  129.     {
  130.         if (ot.gameObject.CompareTag("Destroyable"))
  131.         {
  132.             coll = false;
  133.         }
  134.     }
  135.  
  136.     void SetScoreText()
  137.     {
  138.         scoreText.text = "Score: " + score.ToString ();
  139.     }
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement