Player isnt able to jump, it is running though, tried debug.log, on press of space(jump button) nothing is printing…and my space button is working properly, Im new to unity…pls help me find a remedy?
PFA Ss and working code
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
[SerializeField] float jumpSpeed = 5f;
[SerializeField] float runSpeed = 10f;
Vector2 moveInput;
Rigidbody2D myRigidbody;
Animator myAnimator;
void Start()
{
myRigidbody= GetComponent<Rigidbody2D>();
myAnimator= GetComponent<Animator>();
}
void Update()
{
run();
flipSprite();
}
void OnMove(InputValue value)
{
moveInput=value.Get<Vector2>();
Debug.Log(moveInput);
}
void onJump(InputValue value)
{
if(value.isPressed)
{
// do stuff
myRigidbody.velocity += new Vector2 (0f, jumpSpeed);
Debug.Log("Jumping");
}
}
void run()
{
Vector2 playerVelocity= new Vector2 (moveInput.x * runSpeed, myRigidbody.velocity.y);
myRigidbody.velocity=playerVelocity;
if(Mathf.Abs(myRigidbody.velocity.x)>Mathf.Epsilon)
myAnimator.SetBool("isRunning",true);
else
myAnimator.SetBool("isRunning",false);
}
void flipSprite()
{
bool playerHasHorizontalSpeed = Mathf.Abs(myRigidbody.velocity.x) > Mathf.Epsilon;
if(playerHasHorizontalSpeed)
{
transform.localScale= new Vector2 (Mathf.Sign(myRigidbody.velocity.x), 1f);
}
}
}