Advertisement
kadyr

Untitled

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