kadyr

Untitled

Sep 19th, 2021
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3.  
  4. public class GuyMove : MonoBehaviour
  5. {
  6. public AudioSource jumpSource;
  7.  
  8. [SerializeField]
  9. private float speed = 5f;
  10.  
  11. [SerializeField]
  12. private float jumpSpeed = 10f;
  13.  
  14. //переменная, отвечающая за нашу физику
  15. private Rigidbody rb;
  16.  
  17. public Text ScoreTextTime;
  18. private float scoreTime;
  19.  
  20. private Vector3 direction;
  21.  
  22. //точка респаун
  23. private Vector3 startPosition;
  24.  
  25. private Animator characterAnimator;
  26.  
  27. private bool finishGame;
  28.  
  29. private void Start()
  30. {
  31. rb = GetComponent<Rigidbody>();
  32. characterAnimator = GetComponent<Animator>();
  33. startPosition = transform.position;
  34. }
  35.  
  36. public void ResetPosition()
  37. {
  38. transform.position = startPosition;
  39. }
  40.  
  41. private void Update()
  42. {
  43. if (!finishGame)
  44. {
  45.  
  46. }
  47. //Работа с анимациями
  48.  
  49.  
  50.  
  51. if (isGrounded())
  52. {
  53. characterAnimator.SetFloat("directionValue",direction.magnitude);
  54. if (Input.GetKeyDown(KeyCode.Space))
  55. {
  56. characterAnimator.SetTrigger("jumpTrigger");
  57. rb.AddForce(new Vector3(0, jumpSpeed, 0), ForceMode.Impulse);
  58. jumpSource.Play();
  59. }
  60. }
  61. characterAnimator.SetBool("IsGrounded",isGrounded());
  62.  
  63. }
  64.  
  65. private bool isGrounded()
  66. {
  67. return Physics.Raycast(transform.position, -Vector3.up, 2 + 0.1f);
  68. }
  69. private void FixedUpdate()
  70. {
  71. float horizontal = Input.GetAxis("Horizontal");
  72. float vertical = Input.GetAxis("Vertical");
  73. direction = transform.TransformDirection(new Vector3(horizontal, 0, vertical));
  74. rb.MovePosition(transform.position + direction * speed * Time.deltaTime);
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment