Pro_Unit

JumperMover

Mar 17th, 2020
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.61 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. [RequireComponent(typeof(Rigidbody2D))]
  4. public class JumperMover : MonoBehaviour
  5. {
  6.     [SerializeField] private float _horizontalSpeedMove = 500f;
  7.     private Rigidbody2D _rigidbody2D;
  8.     private float _horizontalInput;
  9.     private void Awake()
  10.     {
  11.         _rigidbody2D = GetComponent<Rigidbody2D>();
  12.     }
  13.     private void Update()
  14.     {
  15.         _horizontalInput = Input.GetAxis("Horizontal");
  16.     }
  17.     private void FixedUpdate()
  18.     {
  19.         _rigidbody2D.velocity = new Vector2(_horizontalInput * _horizontalSpeedMove * Time.fixedDeltaTime, _rigidbody2D.velocity.y);
  20.     }
  21. }
Add Comment
Please, Sign In to add comment