Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- public class PlayerController : MonoBehaviour
- {
- private Rigidbody rb;
- public float speed;
- private int score;
- public Text scoreText;
- public Text winText;
- public int amount_of_hits=0;
- public int needed_hits=2;
- bool coll=false;
- public float small_time = 10.0f;
- bool small=false;
- bool fun = false;
- bool hammer = false;
- void Start ()
- {
- rb = GetComponent<Rigidbody> ();
- score = 0;
- SetScoreText ();
- winText.text = "";
- }
- void Update ()
- {
- if (small == true)
- {
- small_time -= Time.deltaTime;
- if (small_time <= 0)
- {
- small = false;
- small_time = 10.0f;
- transform.localScale += new Vector3 (0.7F, 0.7F, 0.7F);
- transform.position = new Vector3 (GameObject.FindGameObjectWithTag ("Player").transform.position.x, 0.50f, GameObject.FindGameObjectWithTag ("Player").transform.position.z);
- }
- }
- }
- void FixedUpdate ()
- {
- float moveHorizontal = Input.GetAxis ("Horizontal");
- float moveVertial = Input.GetAxis ("Vertical");
- //testowe sterowanie na komputer
- if (fun == false) {
- Vector3 movement = new Vector3 (moveHorizontal, 0, moveVertial);
- rb.AddForce (movement * speed);
- } else {
- Vector3 movement = new Vector3 (-moveHorizontal, 0, -moveVertial);
- rb.AddForce (movement * speed);
- }
- //sterowanie na telefon
- //float moveHorizontal = Input.acceleration.x;
- //float moveVertical = Input.acceleration.z;
- //Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
- //rb.AddForce(movement * speed * Time.deltaTime);
- }
- void OnTriggerEnter(Collider other)
- {
- //podnoszenie rzeczy
- if (other.gameObject.CompareTag ("Pickup")) {
- other.gameObject.SetActive (false);
- score++;
- }
- if ((score >= 8) || (other.gameObject.CompareTag("Meta"))){
- winText.text = "WYGRAŁEŚ!";
- Time.timeScale = 0;
- SetScoreText ();
- }
- //zmiana rozmiaru
- if(other.gameObject.CompareTag("Size"))
- {
- other.gameObject.SetActive(false);
- transform.localScale -= new Vector3(0.7F, 0.7F, 0.7F); //zmniejsza kulkę o podany vector
- 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ą
- small=true;
- }
- //pickupy kolorowe
- if (other.gameObject.CompareTag ("hammer"))
- {
- other.gameObject.SetActive (false);
- hammer = true;
- }
- //zmiana osi sterowania
- if (other.gameObject.CompareTag ("axes")) {
- other.gameObject.SetActive (false);
- fun=true;
- }
- }
- void OnCollisionEnter(Collision ot)
- {
- //rozbijanie ścian
- if (ot.gameObject.CompareTag("Destroyable"))
- {
- if (coll == false && amount_of_hits >= needed_hits)
- {
- coll = true;
- ot.gameObject.SetActive(false);
- }
- else
- {
- coll = true;
- amount_of_hits++;
- }
- }
- if (ot.gameObject.CompareTag ("mur")) {
- if (hammer == true)
- ot.gameObject.SetActive(false);
- }
- }
- void OnCollisionExit(Collision ot)
- {
- if (ot.gameObject.CompareTag("Destroyable"))
- {
- coll = false;
- }
- }
- void SetScoreText()
- {
- scoreText.text = "Score: " + score.ToString ();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement