Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- public class Player_Triggers : MonoBehaviour
- {
- Rigidbody rb;
- //public float speed;
- public Text countText;
- public Text lifeCount;
- public Text winText;
- public Text death;
- public Text remCounter;
- public AudioClip collectSound;
- public AudioClip obSound;
- public AudioClip ambientSound;
- private int count;
- private int lives = 3;
- private int remCount = 15;
- // Start is called before the first frame update
- void Start()
- {
- rb = this.GetComponent<Rigidbody>();
- count = 0;
- SetCountText();
- SetremText();
- winText.text = "";
- death.text = "";
- SetLifeCount();
- lives = 0;
- }
- void OnCollisionEnter(Collision collision)
- {
- if (collision.gameObject.tag == "Enemy")
- {
- //text.text = "You Win";
- transform.position = new Vector3(0, 0, 0);
- lives = lives - 1;
- SetLifeCount();
- AudioSource.PlayClipAtPoint(obSound, transform.position);
- }
- if (collision.gameObject.CompareTag("Pellet"))
- {
- collision.gameObject.SetActive(false);
- //gameObject.SetActive(false);
- count = count + 1;
- AudioSource.PlayClipAtPoint(collectSound, transform.position);
- SetCountText();
- remCount = remCount - 1;
- SetremText();
- }
- }
- void SetCountText()
- {
- countText.text = "Collected: " + count.ToString();
- if (count >= 15)
- {
- winText.text = "You Win!";
- }
- }
- //}
- void SetremText()
- {
- remCounter.text = "Remaining: " + remCount.ToString();
- }
- void SetLifeCount()
- {
- lifeCount.text = "Lives : " + lives.ToString();
- if (lives == 0)
- {
- death.text = "Game Over";
- //yield WaitForSeconds(5.0); // or however long you want it to wait
- //Application.LoadLevel(Application.loadedLevel);
- //yield return new WaitForSeconds(5.0f);
- SceneManager.LoadScene(SceneManager.GetActiveScene().name);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement