Advertisement
GoldenTacktical

2d Character Movement (Unity C#)

Oct 24th, 2019
8,257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.52 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class player : MonoBehaviour
  7. {
  8.  
  9.     public Rigidbody2D rb;
  10.     public float move = 0f;
  11.     public float speed = 20f;
  12.  
  13.     void Start()
  14.     {
  15.         rb = GetComponent<Rigidbody2D>();
  16.     }
  17.  
  18.     // Update is called once per frame
  19.     void Update()
  20.     {
  21.         move = Input.GetAxis("Horizontal");
  22.     }
  23.  
  24.     void FixedUpdate()
  25.     {
  26.         rb.velocity = new Vector2 (move * speed, rb.velocity.y);
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement