Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6.  
  7. public class Player_Triggers : MonoBehaviour
  8. {
  9.  
  10. Rigidbody rb;
  11.  
  12. //public float speed;
  13.  
  14. public Text countText;
  15.  
  16. public Text lifeCount;
  17.  
  18. public Text winText;
  19.  
  20. public Text death;
  21.  
  22. public Text remCounter;
  23.  
  24. public AudioClip collectSound;
  25.  
  26. public AudioClip obSound;
  27.  
  28. public AudioClip ambientSound;
  29.  
  30. private int count;
  31.  
  32. private int lives = 3;
  33.  
  34. private int remCount = 15;
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. // Start is called before the first frame update
  43. void Start()
  44. {
  45. rb = this.GetComponent<Rigidbody>();
  46.  
  47. count = 0;
  48.  
  49. SetCountText();
  50.  
  51. SetremText();
  52.  
  53. winText.text = "";
  54.  
  55. death.text = "";
  56.  
  57. SetLifeCount();
  58.  
  59. lives = 0;
  60.  
  61.  
  62. }
  63.  
  64.  
  65.  
  66.  
  67. void OnCollisionEnter(Collision collision)
  68. {
  69. if (collision.gameObject.tag == "Enemy")
  70. {
  71. //text.text = "You Win";
  72. transform.position = new Vector3(0, 0, 0);
  73. lives = lives - 1;
  74. SetLifeCount();
  75. AudioSource.PlayClipAtPoint(obSound, transform.position);
  76. }
  77.  
  78. if (collision.gameObject.CompareTag("Pellet"))
  79. {
  80. collision.gameObject.SetActive(false);
  81. //gameObject.SetActive(false);
  82. count = count + 1;
  83. AudioSource.PlayClipAtPoint(collectSound, transform.position);
  84. SetCountText();
  85. remCount = remCount - 1;
  86. SetremText();
  87.  
  88.  
  89. }
  90. }
  91.  
  92. void SetCountText()
  93. {
  94. countText.text = "Collected: " + count.ToString();
  95. if (count >= 15)
  96. {
  97. winText.text = "You Win!";
  98. }
  99. }
  100. //}
  101.  
  102. void SetremText()
  103. {
  104. remCounter.text = "Remaining: " + remCount.ToString();
  105.  
  106. }
  107.  
  108. void SetLifeCount()
  109. {
  110. lifeCount.text = "Lives : " + lives.ToString();
  111.  
  112. if (lives == 0)
  113. {
  114. death.text = "Game Over";
  115. //yield WaitForSeconds(5.0); // or however long you want it to wait
  116. //Application.LoadLevel(Application.loadedLevel);
  117. //yield return new WaitForSeconds(5.0f);
  118. SceneManager.LoadScene(SceneManager.GetActiveScene().name);
  119. }
  120. }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement