Getting Error on Jump Methode please help

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.InputSystem;

public class PlayerMovement : MonoBehaviour

{

Vector2 moveInput;

Rigidbody2D myrigidbody2D;

[SerializeField] float moveSpeed =10f;

[SerializeField] float jumpSpeed = 10f;

Animator myAnimator;



// Start is called before the first frame update

void Start()

{

    myrigidbody2D = GetComponent<Rigidbody2D>();

    myAnimator = GetComponent<Animator>();

}

// Update is called once per frame

void Update()

{

    Run();  

    FlipSprite();

    Jump();

}

void OnMove (InputValue value)

{

  moveInput = value.Get<Vector2>();

 

}

void Run()

{

  Vector2 playerVelocity = new Vector2 (moveInput.x * moveSpeed, myrigidbody2D.velocity.y);  

  myrigidbody2D.velocity = playerVelocity;

       

}

void FlipSprite()

{

   bool playerHashorizontalSpeed =Mathf.Abs(myrigidbody2D.velocity.x) > Mathf.Epsilon;

   if(playerHashorizontalSpeed)

   {

      transform.localScale = new Vector2 (Mathf.Sign(myrigidbody2D.velocity.x),1f);

      myAnimator.SetBool("isRunning",true);

   }

    else

    {

      myAnimator.SetBool("isRunning",false);

    }

}

void Jump(InputValue value)

{

  if(value.isPressed)

  {

    myrigidbody2D.velocity += new Vector2(0f, jumpSpeed);

  }

}

}

Hi Samar,

Welcome to our community! :slight_smile:

According to the code you shared, the Jump method is defined with a parameter. This means that you have to pass on an argument during the method call. Jump() in Update is invalid.

Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture?


See also:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms