UnityProjekt/Assets/CharacterController.cs

22 lines
No EOL
491 B
C#

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<Rigidbody2D>();
}
// 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));
}
}