2D-Animation icon indicating copy to clipboard operation
2D-Animation copied to clipboard

Calls jump function multiple times.

Open ItsSeendo opened this issue 1 year ago • 0 comments

I tried following the tutorial and i got all the way to the end and when I tested it, it called the jump event both when it originally jumps and when it lands. any ideas? `using System.Collections; using System.Collections.Generic; using UnityEngine;

public class playerMovement : MonoBehaviour { public movementScript ms; public Animator animator; public bool jumpAction; private bool playerStopped; private float stopTimer;

public float horizontalMovement;

public float runSpeed = 40f;
public bool jump;
public bool crouch;

// Update is called once per frame
void Update()
{
    horizontalMovement = Input.GetAxisRaw("Horizontal") * runSpeed;

	animator.SetFloat("Speed", Mathf.Abs(horizontalMovement));

	if (Input.GetButtonDown("Jump"))
	{
		jump = true;
		animator.SetBool("IsJumping", true);
	}

	if (Input.GetButtonDown("Crouch"))
	{
		crouch = true;
	} else if (Input.GetButtonUp("Crouch"))
	{
		crouch = false;
	}

    if(stopTimer >= 10)
    {
        animator.SetBool("IsSitting", true);
    }
    else if(stopTimer < 10)
    {
        animator.SetBool("IsSitting", false);
    }
}

public void OnLanding () { animator.SetBool("IsJumping", false); Debug.Log("Player Landed"); }

public void OnCrouching (bool isCrouching)
{
	animator.SetBool("IsCrouching", isCrouching);
}

void FixedUpdate ()
{
	// Move our character
	ms.Move(horizontalMovement * Time.fixedDeltaTime, crouch, jump);
	jump = false;
}

}`

ItsSeendo avatar Jan 26 '23 21:01 ItsSeendo