So im trying to make a jumping animation stop happening once ive touched the ground, ive set up the animator, ive set up the isJump bool in the script, and i have a small controller thats about jumping. However the OnLanding() Event isnt triggering:
Player Movement:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveBoi : MonoBehaviour
{
public float speed;
public float jump;
public Animator animator;
bool faceRight = true;
[SerializeField]
public ControllerBoi2D controller;
private float move;
private Rigidbody2D rb;
private bool isJump = false;
// Start is called before the first frame update
void Start()
{
transform.position = new Vector2(0, -4.956f);
rb = GetComponent<Rigidbody2D>();
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
move = Input.GetAxisRaw("Horizontal"); //sharper
animator.SetFloat("Speed", Mathf.Abs(move));// acces the animator to allow the animation to happen.
rb.velocity = new Vector2(move * speed, rb.velocity.y);
if(Input.GetButtonDown("Jump"))
{
rb.AddForce(new Vector2(rb.velocity.x, jump));
animator.SetBool("isJump", true);
isJump = true;
}
if (move < 0 && faceRight)
{
flip(); //basically if left key pressed and ur facing right, then you'll face left ii
}
else if(move > 0 && !faceRight)
{
flip();
}
}
void flip()
{
faceRight = !faceRight;//if false itll be true, same with true
transform.Rotate(0f, 180f, 0f);
}
public void OnLanding()
{
animator.SetBool("isJump", false);
Debug.Log("OnLanding triggered");
}
}
Controller:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class ControllerBoi2D : MonoBehaviour
{
Animator animator;
Rigidbody2D rb;
[SerializeField]
Transform groundCheckCollide;
[SerializeField]
LayerMask groundLayer;
private LayerMask m_WhatIsGround;
const float groundCheckRadius = 0.2f;
[SerializeField]
bool isGrounded = false;
[Header("Events")]
[Space]
public UnityEvent LandingEvent;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void FixedUpdate()
{
GroundCheck();
}
void GroundCheck()
{
isGrounded = false;
isGrounded = Physics2D.OverlapCircle(groundCheckCollide.position, groundCheckRadius, groundLayer);
}
}
For some reason the OnLanding Event isnt triggering even though ive applied it to the controller in the inspector. I just need the jumping animation to stop once i land on the ground. Could you help? Thanks!