Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class movementScript : MonoBehaviour
  6. {
  7.     [Range(2,20)]
  8.     public float forwardSpeed;
  9.  
  10.     [Range(2, 15)]
  11.     public float backwardSpeed;
  12.  
  13.     [Range(2, 10)]
  14.     public float sideSpeed;
  15.  
  16.     [Range(1, 300)]
  17.     public int mouseSensibility;
  18.     // Start is called before the first frame update
  19.     void Start()
  20.     {
  21.        
  22.     }
  23.  
  24.     // Update is called once per frame
  25.     void LateUpdate()
  26.     {
  27.         transform.eulerAngles += new Vector3(0, Input.GetAxis("Mouse X") * mouseSensibility, 0);
  28.         if (Input.anyKey)
  29.         {
  30.             InputManagement();
  31.         }    
  32.     }
  33.  
  34.     void InputManagement()
  35.     {
  36.         if(Input.GetKey(KeyCode.Z))
  37.         {
  38.             transform.position = transform.position + new Vector3(0, 0, forwardSpeed * Time.deltaTime);
  39.         }
  40.         if (Input.GetKey(KeyCode.S))
  41.         {
  42.             transform.position -= new Vector3(0, 0, backwardSpeed * Time.deltaTime);
  43.         }
  44.         if (Input.GetKey(KeyCode.Q))
  45.         {
  46.             transform.position -= new Vector3(sideSpeed * Time.deltaTime, 0, 0);
  47.         }
  48.         if (Input.GetKey(KeyCode.D))
  49.         {
  50.             transform.position += new Vector3(sideSpeed * Time.deltaTime, 0, 0);
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement