playerController script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
private Rigidbody playerRb;
public float speed;
public float jumpForce;
// Start is called before the first frame update
void Start()
{
playerRb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate()
{
float horizontalInput = Input.GetAxisRaw("Horizontal");
playerRb.velocity = new Vector2(horizontalInput * speed, playerRb.velocity.y);
}
private void Update()
{
if (Input.GetButtonDown("Jump"))
{
playerRb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
}
}
}