This is my code , I see it from a video on YT and I dont know de problem
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class movej : MonoBehaviour {
public float moveSpeed;
public float jump;
bool grounded = false;
void Update()
{
if (Input.GetKey(KeyCode.RightArrow))
transform.Translate(Vector3.right * moveSpeed * Time.deltaTime);
if (Input.GetKey(KeyCode.LeftArrow))
transform.Translate(-Vector2.right * moveSpeed * Time.deltaTime);
if (Input.GetKeyDown(KeyCode.Space))
{
if (grounded) {
GetComponent<Rigidbody2D>().velocity = new Vector2(
GetComponent<Rigidbody2D>().velocity.x, jump);
}
}
}
void OnTriggerEnter2D()
{
grounded = true;
}
void OnTriggerExit2D()
{
grounded = false;
}
}