Advertisement
kadyr

Untitled

Aug 14th, 2021
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3.  
  4. public class GuyMove : MonoBehaviour
  5. {
  6. [SerializeField]
  7. private float speed = 5f;
  8.  
  9. [SerializeField]
  10. private float jumpSpeed = 10f;
  11.  
  12. //переменная, отвечающая за нашу физику
  13. private Rigidbody rb;
  14.  
  15. public Text ScoreTextTime;
  16. private float scoreTime;
  17.  
  18. private Vector3 direction;
  19.  
  20. //точка респаун
  21. private Vector3 startPosition;
  22.  
  23. private bool finishGame;
  24.  
  25. private void Start()
  26. {
  27. rb = GetComponent<Rigidbody>();
  28. startPosition = transform.position;
  29. }
  30.  
  31. public void ResetPosition()
  32. {
  33. transform.position = startPosition;
  34. }
  35.  
  36. private void Update()
  37. {
  38. if (!finishGame)
  39. {
  40. scoreTime += Time.deltaTime;
  41. ScoreTextTime.text = scoreTime.ToString();
  42. }
  43.  
  44. if (Input.GetKeyDown(KeyCode.Space))
  45. //реализация прыжка
  46. rb.AddForce(new Vector3(0, jumpSpeed, 0), ForceMode.Impulse);
  47. }
  48.  
  49. private void FixedUpdate()
  50. {
  51. float horizontal = Input.GetAxis("Horizontal");
  52. float vertical = Input.GetAxis("Vertical");
  53. direction = transform.TransformDirection(new Vector3(horizontal, 0, vertical));
  54. rb.MovePosition(transform.position + direction * speed * Time.deltaTime);
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement