using System.Collections; using System.Collections.Generic; using UnityEngine; public class CharacterController : MonoBehaviour { private Rigidbody2D rb; // Start is called before the first frame update void Start() { rb = GetComponent(); } // Update is called once per frame void Update() { if (Mathf.Abs(rb.velocity.x) > 10) return; rb.AddForce(new Vector2(Input.GetAxis("Horizontal") * 5, 0)); } }