Facebook
From Buff Hamster, 9 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 96
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerController : MonoBehaviour
  6. {
  7.     [Range(1f, 100f)] [SerializeField] float movementSpeed = 1f;
  8.     [SerializeField] float rotationSpeed = 1f;
  9.     [SerializeField] Rigidbody rb;
  10.     [SerializeField] float jumpForce;
  11.  
  12.     // Update is called once per frame
  13.     void Update()
  14.     {
  15.         if (Input.GetKeyDown (KeyCode.LeftShift))
  16.         {
  17.             movementSpeed = 4f;
  18.         }
  19.         var x = Input.GetAxis("Horizontal") * Time.deltaTime * 150.0f * rotationSpeed;
  20.         var z = Input.GetAxis("Vertical") * Time.deltaTime * 3.0f * movementSpeed;
  21.  
  22.         transform.Rotate(0, x, 0);
  23.         transform.Translate(0, 0, z);
  24.  
  25.         if(Input.GetKeyDown(KeyCode.Space))
  26.         {
  27.             rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
  28.         }
  29.     }
  30. }
  31.