Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class PlayerControler : MonoBehaviour
- {
- public float speed;
- public GUIText countText;
- public GUIText WinText;
- private int count;
- private int cur_Level;
- private int Level_cap;
- public AudioClip Pickup_S;
- public AudioClip Win_S;
- public Vector3 lastGoodPosition;
- public Vector3 gravity;
- void Start ()
- {
- count = 0;
- cur_Level = 0;
- Level_cap = 4;
- SetCountText ();
- WinText.text = "";
- Physics.gravity = gravity;
- }
- void FixedUpdate()
- {
- float moveHorizontal = Input.GetAxis("Horizontal");
- float moveVertical = Input.GetAxis("Vertical");
- Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
- rigidbody.AddForce(movement * speed * Time.deltaTime);
- //if (gameObject.tag == "Player")
- //{
- // Application.LoadLevel (Application.loadedLevel);
- // }
- }
- void OnTriggerEnter(Collider other)
- {
- if (other.gameObject.tag == "Pickup")
- {
- audio.PlayOneShot(Pickup_S, 0.7F);
- other.gameObject.SetActive(false);
- count = count + 1;
- SetCountText();
- }
- }
- void OnCollisionEnter(Collision collision)
- {
- if (collision.collider.tag == "Player")
- {
- lastGoodPosition = transform.position;
- }
- else if (collision.collider.tag == "PlaneofDeath")
- {
- transform.position = lastGoodPosition;
- }
- }
- void SetCountText()
- {
- countText.text = "Count: " + count.ToString();
- if (count >= 20)
- {
- WinText.text = "You WIN!";
- audio.PlayOneShot(Win_S, 0.7F);
- Level_cap = cur_Level +1;
- StartCoroutine(NextLevel());
- }
- }
- IEnumerator NextLevel()
- {
- yield return new WaitForSeconds(3);
- int i = Application.loadedLevel;
- //Application.LoadLevel(i + 1);
- if (i<=Level_cap)
- {
- Application.LoadLevel(i + 1);
- }
- else if (i>Level_cap)
- {
- Application.LoadLevel(0);
- }
- }
- }
Advertisement
RAW Paste Data
Copied
Advertisement