Advertisement
leomovskii

Ride

Sep 28th, 2024
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.60 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class Ride : MonoBehaviour {
  4.  
  5.     public float moveSpeed = 15f;
  6.     public float turnSpeed = 0.2f;
  7.  
  8.     private Rigidbody rb;
  9.     private float moveInput;
  10.  
  11.     private void Start() {
  12.         rb = GetComponent<Rigidbody>();
  13.     }
  14.  
  15.     private void Update() { // оновленні екрану
  16.         moveInput = Input.GetAxis("Vertical");
  17.  
  18.         float turnInput = Input.GetAxis("Horizontal");
  19.         transform.Rotate(0f, turnInput * turnSpeed, 0f);
  20.     }
  21.  
  22.     private void FixedUpdate() { // сталі проміжки часу (0.02с == 50 фпс)
  23.         rb.AddForce(moveInput * moveSpeed * transform.forward);
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement