Advertisement
kadyr

Untitled

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