Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class GuyMove : MonoBehaviour
- {
- private Rigidbody rb; // компонент Rigidbody
- public float speed = 5;
- Vector3 direction;
- Vector3 startPosition; // начальное положение
- [SerializeField] // this
- private AudioSource jumpAudioSource; //this
- private Animator playerAniamtor; //this 2
- void Start()
- {
- startPosition = transform.position;
- rb = GetComponent<Rigidbody>();
- playerAniamtor = GetComponent<Animator>(); // this 2
- }
- private void Update()
- {
- if (finish == false)
- {
- time += Time.deltaTime;
- timeText.text = time.ToString();
- }
- if (isGrounded())
- {
- playerAniamtor.SetFloat("directionValue",direction.magnitude);
- if (Input.GetKeyDown(KeyCode.Space))
- {
- playerAniamtor.SetTrigger("JumpTrigger");
- jumpAudioSource.Play();
- rb.AddForce(new Vector3(0, 20, 0), ForceMode.Impulse);
- }
- }
- playerAniamtor.SetBool("isGrounded",isGrounded());
- if (transform.position.y < -10)
- {
- transform.position = startPosition;
- }
- }
- private bool isGrounded()
- {
- return Physics.Raycast(transform.position, -Vector3.up, 2 + 0.1f);
- }
- void FixedUpdate()
- {
- float horizontal = Input.GetAxis("Horizontal");
- float vertical = Input.GetAxis("Vertical");
- direction = transform.TransformDirection(horizontal, 0, vertical);
- rb.MovePosition(transform.position + speed * direction * Time.deltaTime);
- }
- float time = 0;
- bool finish = false;
- [SerializeField] Text timeText;
- private void OnTriggerEnter(Collider other)
- {
- if (other.tag == "Finish")
- {
- finish = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement