Advertisement
kadyr

Untitled

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