lemansky

Untitled

Feb 26th, 2021
670
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerMove : MonoBehaviour
  6. {
  7.     [SerializeField]
  8.     float _speed = 10.0f;
  9.     float _jumpForce = 20.0f;
  10.     Vector3 _movement;
  11.     Rigidbody _rb;
  12.     bool _canJump;
  13.     // Start is called before the first frame update
  14.  
  15.     void Start()
  16.     {
  17.         _rb = this.GetComponent<Rigidbody>();
  18.     }
  19.  
  20.     // Update is called once per frame
  21.     void Update()
  22.     {
  23.         if (Input.GetKeyDown(KeyCode.Space))
  24.         {
  25.             _canJump = true;
  26.         }
  27.     }
  28.  
  29.     private void FixedUpdate()
  30.     {
  31.         _movement = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
  32.         if (_canJump)
  33.         {
  34.             _movement.y = _jumpForce;
  35.             _canJump = false;
  36.         }
  37.         _rb.AddForce(_movement * _speed);
  38.     }
  39. }
  40.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×