Advertisement
kadyr

Untitled

Aug 24th, 2021
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. using UnityEngine.UI; // Добавление директивы
  6.  
  7. public class PlayerMove : MonoBehaviour
  8. {
  9. void Start()
  10. {
  11. Debug.Log("Press F to pay respect!");
  12. ChangeHealth(-20);
  13. }
  14. [SerializeField] CharacterController controller;
  15. [SerializeField] float speed = 5f;
  16. [SerializeField] float gravity = 50;
  17. [SerializeField] float jumpForce = 40;
  18.  
  19. int crystalCount = 0;
  20. float score = 50f;
  21.  
  22. int health = 100;
  23. public Text scoreText; // ТЕКСТ
  24. public Text timeText; //время нашего таймера (визуализация)
  25. public Text resultText; // результат = поражение/победа
  26. public Text hpText;
  27. private Vector3 direction;
  28.  
  29. [SerializeField] float timeToWin = 10f;
  30. bool lose = false;
  31.  
  32. public void ChangeHealth(int hp)
  33. {
  34. health += hp;
  35. hpText.text = health.ToString();
  36. if(health <= 0)
  37. {
  38. Cursor.lockState = CursorLockMode.None;
  39. SceneManager.LoadScene(2);
  40. }
  41. }
  42.  
  43.  
  44. void Update()
  45. {
  46. //timeToWin -= Time.deltaTime;
  47. //timeText.text = timeToWin.ToString();
  48. //if(timeToWin <0 && lose == false){
  49. // lose = true;
  50. // Debug.Log("Ты проиграл");
  51. // resultText.gameObject.SetActive(true);
  52. // resultText.text = "Ты проиграл!!!!";
  53.  
  54. //}
  55. float moveHorizontal = Input.GetAxis("Horizontal");
  56. float moveVertical = Input.GetAxis("Vertical");
  57.  
  58. if (controller.isGrounded)
  59. {
  60. direction = new Vector3(moveHorizontal, 0, moveVertical);
  61.  
  62. direction = transform.TransformDirection(direction) * speed;
  63. if(Input.GetKey(KeyCode.LeftShift)){
  64. speed = 20f;
  65. }
  66. if(Input.GetKeyUp(KeyCode.LeftShift)){
  67. speed = 5f;
  68. }
  69.  
  70.  
  71. if (Input.GetKey(KeyCode.Space))
  72. {
  73. direction.y = jumpForce;
  74. }
  75.  
  76. }
  77.  
  78. //Если будете добавлять что-то связанное с управлением, делайте это здесь
  79.  
  80. direction.y -= gravity * Time.deltaTime;
  81. controller.Move(direction * Time.deltaTime);
  82. }
  83.  
  84. private void OnTriggerEnter(Collider trigObject) {
  85. if(trigObject.gameObject.tag == "Crystal"){
  86. crystalCount +=1;
  87. scoreText.text = crystalCount.ToString();
  88. Destroy(trigObject.gameObject);
  89. Debug.Log(crystalCount);
  90. if(crystalCount == 5){
  91. resultText.gameObject.SetActive(true);
  92. resultText.text = "Ты победил!";
  93. Debug.Log("Ты победил!!!");
  94. }
  95. }
  96. }
  97. }
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement