Advertisement
GauHelldragon

Untitled

Feb 24th, 2022
855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class P1Script : MonoBehaviour
  6. {
  7.     public Rigidbody rb;
  8.     public float speed = 2.5f;
  9.     private bool left = false;
  10.     private bool right = false;
  11.     private bool down = false;
  12.     private bool up = false;
  13.     private float velH = 0.0f;
  14.     private float velV = 0.0f;
  15.  
  16.  
  17.     // Start is called before the first frame update
  18.     void Start()
  19.     {
  20.         rb = GetComponent<Rigidbody>();
  21.  
  22.  
  23.     }
  24.  
  25.     // Update is called once per frame
  26.     void Update()
  27.     {
  28.         if (Input.GetKey(KeyCode.A))
  29.         {
  30.             left = true;            
  31.         }
  32.         if (Input.GetKeyUp(KeyCode.A))
  33.         {
  34.             left = false;            
  35.         }
  36.         if (Input.GetKey(KeyCode.D))
  37.         {
  38.             right = true;
  39.         }
  40.         if (Input.GetKeyUp(KeyCode.D))
  41.         {
  42.             right = false;
  43.         }
  44.  
  45.         velH = 0;
  46.         if ( left )
  47.         {
  48.             velH++;
  49.         }
  50.         if (right)
  51.         {
  52.             velH--;
  53.         }
  54.  
  55.         if (Input.GetKey(KeyCode.W))
  56.         {
  57.             up = true;
  58.         }
  59.         if (Input.GetKeyUp(KeyCode.W))
  60.         {
  61.             up = false;
  62.         }
  63.         if (Input.GetKey(KeyCode.S))
  64.         {
  65.             down = true;
  66.         }
  67.         if (Input.GetKeyUp(KeyCode.S))
  68.         {
  69.             down = false;
  70.         }
  71.  
  72.         velV = 0;
  73.         if (up)
  74.         {
  75.             velV++;
  76.         }
  77.         if (down)
  78.         {
  79.             velV--;
  80.         }
  81.  
  82.         rb.velocity = (new Vector3(velV, 0, velH) * speed);
  83.  
  84.     }
  85. }
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement