Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calls jump function multiple times. #6

Open
ItsSeendo opened this issue Jan 26, 2023 · 0 comments
Open

Calls jump function multiple times. #6

ItsSeendo opened this issue Jan 26, 2023 · 0 comments

Comments

@ItsSeendo
Copy link

ItsSeendo commented Jan 26, 2023

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;
}

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant