Unity 2D Character Movement Horizontal
In this video, you can learn how an object, for example, a character, moves in unity. Here, a cube is provided to move left and right with c sharp codes on the horizontal axis. In the video, you will see how to add box collider and rigidbody 2d features to the object and how a new script is written. Source codes are below ; Unity 2D Move Objects Horizontal Movement, Moving script in unit 2d, How to move character in Unity 2D, PlayerController script C# ; using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerController : MonoBehaviour { private float horizontal; public float speed = 5f; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { horizontal = Input.GetAxis("Horizontal"); horizontal *= speed * Time.deltaTime; transform.Translate(new Vector3(horizontal, 0f, 0f)); } }
Download
0 formatsNo download links available.