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; // Добавление директивы
- public class PlayerMove : MonoBehaviour
- {
- void Start()
- {
- Debug.Log("Press F to pay respect!");
- }
- [SerializeField] CharacterController controller;
- [SerializeField] float speed = 5f;
- [SerializeField] float gravity = 50;
- [SerializeField] float jumpForce = 40;
- int crystalCount = 0;
- float score = 50f;
- public Text scoreText; // ТЕКСТ
- public Text timeText;
- private Vector3 direction;
- [SerializeField] float timeToWin = 10f;
- bool lose = false;
- void Update()
- {
- timeToWin -= Time.deltaTime;
- timeText.text = timeToWin.ToString();
- if(timeToWin <0 && lose == false){
- lose = true;
- Debug.Log("Ты проиграл");
- }
- float moveHorizontal = Input.GetAxis("Horizontal");
- float moveVertical = Input.GetAxis("Vertical");
- if (controller.isGrounded)
- {
- direction = new Vector3(moveHorizontal, 0, moveVertical);
- direction = transform.TransformDirection(direction) * speed;
- if(Input.GetKey(KeyCode.LeftShift)){
- speed = 20f;
- }
- if(Input.GetKeyUp(KeyCode.LeftShift)){
- speed = 5f;
- }
- if (Input.GetKey(KeyCode.Space))
- {
- direction.y = jumpForce;
- }
- }
- //Если будете добавлять что-то связанное с управлением, делайте это здесь
- direction.y -= gravity * Time.deltaTime;
- controller.Move(direction * Time.deltaTime);
- }
- private void OnTriggerEnter(Collider trigObject) {
- if(trigObject.gameObject.tag == "Crystal"){
- crystalCount +=1;
- scoreText.text = crystalCount.ToString();
- Destroy(trigObject.gameObject);
- Debug.Log(crystalCount);
- if(crystalCount == 5){
- Debug.Log("Ты победил!!!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement