i made the game object, i created the code but my character still jumps mutiple times this is the code for my player:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public float moveSpeed;
float xInput, yInput;
Vector2 targetPos;
Rigidbody2D rb;
public float jumpForce;
bool isGrounded;
public Transform groundCheck;
public LayerMask groundlayer;
public Vector3 respawnPoint;
private void Awake()
{
rb = GetComponent();
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(Input.GetKeyDown(KeyCode.Space))
{
if(isGrounded)
{
Jump();
}
}
}
private void FixedUpdate()
{
xInput = Input.GetAxis("Horizontal");
yInput = Input.GetAxis("Vertical");
transform.Translate(xInput * moveSpeed, yInput * moveSpeed, 0);
PlatformerMove();
isGrounded = Physics2D.OverlapCircle(groundCheck.position,0.2f,groundlayer);
}
void Jump()
{
rb.velocity = Vector2.up * jumpForce;
}
void PlatformerMove()
{
rb.velocity = new Vector2(moveSpeed * xInput, rb.velocity.y);
}
void OnTriggerEnter2D(Collider2D other)
{
if(other.tag == "Fall Detector")
{
transform.position = respawnPoint;
}
}
}