Advertisement
kadyr

Untitled

Jul 10th, 2021
895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.20 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.  
  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.         }
  35.         float moveHorizontal = Input.GetAxis("Horizontal");
  36.         float moveVertical = Input.GetAxis("Vertical");
  37.  
  38.         if (controller.isGrounded)
  39.         {
  40.             direction = new Vector3(moveHorizontal, 0, moveVertical);
  41.  
  42.             direction = transform.TransformDirection(direction) * speed;
  43.             if(Input.GetKey(KeyCode.LeftShift)){
  44.                 speed = 20f;
  45.             }
  46.             if(Input.GetKeyUp(KeyCode.LeftShift)){
  47.                 speed = 5f;
  48.             }
  49.  
  50.  
  51.             if (Input.GetKey(KeyCode.Space))
  52.             {
  53.                 direction.y = jumpForce;
  54.             }
  55.  
  56.         }
  57.        
  58.         //Если будете добавлять что-то связанное с управлением, делайте это здесь
  59.        
  60.         direction.y -= gravity * Time.deltaTime;
  61.         controller.Move(direction * Time.deltaTime);
  62.     }
  63.  
  64.     private void OnTriggerEnter(Collider trigObject) {
  65.         if(trigObject.gameObject.tag == "Crystal"){
  66.             crystalCount +=1;
  67.             scoreText.text = crystalCount.ToString();
  68.             Destroy(trigObject.gameObject);
  69.             Debug.Log(crystalCount);
  70.             if(crystalCount == 5){
  71.                 Debug.Log("Ты победил!!!");
  72.             }
  73.         }
  74.     }
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement