Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- public class GuyMove : MonoBehaviour
- {
- public AudioSource jumpSource;
- [SerializeField]
- private float speed = 5f;
- [SerializeField]
- private float jumpSpeed = 10f;
- //переменная, отвечающая за нашу физику
- private Rigidbody rb;
- public Text ScoreTextTime;
- private float scoreTime;
- private Vector3 direction;
- //точка респаун
- private Vector3 startPosition;
- private Animator characterAnimator;
- private bool finishGame;
- private void Start()
- {
- rb = GetComponent<Rigidbody>();
- characterAnimator = GetComponent<Animator>();
- startPosition = transform.position;
- }
- public void ResetPosition()
- {
- transform.position = startPosition;
- }
- private void Update()
- {
- if (!finishGame)
- {
- scoreTime += Time.deltaTime;
- ScoreTextTime.text = scoreTime.ToString();
- }
- //Работа с анимациями
- if (isGrounded())
- {
- characterAnimator.SetFloat("directionValue",direction.magnitude);
- if (Input.GetKeyDown(KeyCode.Space))
- {
- characterAnimator.SetTrigger("jumpTrigger");
- rb.AddForce(new Vector3(0, jumpSpeed, 0), ForceMode.Impulse);
- jumpSource.Play();
- }
- }
- characterAnimator.SetBool("IsGrounded",isGrounded());
- }
- private bool isGrounded()
- {
- return Physics.Raycast(transform.position, -Vector3.up, 2 + 0.1f);
- }
- private void FixedUpdate()
- {
- float horizontal = Input.GetAxis("Horizontal");
- float vertical = Input.GetAxis("Vertical");
- direction = transform.TransformDirection(new Vector3(horizontal, 0, vertical));
- rb.MovePosition(transform.position + direction * speed * Time.deltaTime);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement