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.SceneManagement;
- using UnityEngine.UI; // Добавление директивы
- public class PlayerMove : MonoBehaviour
- {
- void Start()
- {
- Debug.Log("Press F to pay respect!");
- ChangeHealth(-20);
- }
- [SerializeField] CharacterController controller;
- [SerializeField] float speed = 5f;
- [SerializeField] float gravity = 50;
- [SerializeField] float jumpForce = 40;
- int crystalCount = 0;
- float score = 50f;
- int health = 100;
- public Text scoreText; // ТЕКСТ
- public Text timeText; //время нашего таймера (визуализация)
- public Text resultText; // результат = поражение/победа
- public Text hpText;
- private Vector3 direction;
- [SerializeField] float timeToWin = 10f;
- bool lose = false;
- public void ChangeHealth(int hp)
- {
- health += hp;
- hpText.text = health.ToString();
- if(health <= 0)
- {
- Cursor.lockState = CursorLockMode.None;
- SceneManager.LoadScene(2);
- }
- }
- void Update()
- {
- //timeToWin -= Time.deltaTime;
- //timeText.text = timeToWin.ToString();
- //if(timeToWin <0 && lose == false){
- // lose = true;
- // Debug.Log("Ты проиграл");
- // resultText.gameObject.SetActive(true);
- // resultText.text = "Ты проиграл!!!!";
- //}
- 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){
- resultText.gameObject.SetActive(true);
- resultText.text = "Ты победил!";
- Debug.Log("Ты победил!!!");
- }
- }
- if (trigObject.tag == "healbag")
- {
- Destroy(trigObject.gameObject);
- ChangeHealth(50);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement