Home > Back-end >  how do i fix my grappling hook script bug
how do i fix my grappling hook script bug

Time:05-11

im making a game similar to karlson and struggling to fix this line of code to stop a bug the bug is the grappling gun stuck in grappling mode while the player is not holding down the mouse button the code i want to do is an if statement to check if the bool is true and Input.GetMouseButtonUp is not happening

***if ((bool)IsGrappling = true) && (Input.GetMouseButtonUp(0))){
    StopGrapple;
}***

here is the code

CodePudding user response:

if (IsGrappling == true && Input.GetMouseButtonUp(0))
{
    StopGrapple;
}

OR

if (IsGrappling && Input.GetMouseButtonUp(0))
{
    StopGrapple;
}

CodePudding user response:

I write the difference between these three codes here.

Input.GetMouseButton: The function is executed continuously as long as the key is pressing.

Input.GetMouseButtonDown: When you press the mouse button, only the first frame.

Input.GetMouseButtonUp: When you release the mouse button, only the first frame.

the operator != and ! in c# Can reverse the condition. For that case:

    if (IsGrappling && !Input.GetMouseButton(0))
    {
        // do something
    }
  • Related