my player is not triggering and climbing.
my inspectors
my script
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
Rigidbody2D rb;
Vector2 _moveinput;
[SerializeField] float _movespeed = 10f;
[SerializeField] float _jumpspeed = 5f;
[SerializeField] float _climbspeed = 5f;
Animator _animator;
CapsuleCollider2D _capsulecollider;
bool _isTouchingLadder = false;
void Start()
{
rb = GetComponent<Rigidbody2D>();
_animator = GetComponent<Animator>();
_capsulecollider = GetComponent<CapsuleCollider2D>();
}
void Update()
{
Run();
FlipSprite();
ClimbLadder();
}
void OnMove(InputValue value)
{
_moveinput = value.Get<Vector2>();
}
void OnJump(InputValue value)
{
if (!_capsulecollider.IsTouchingLayers(LayerMask.GetMask("Ground")))
{
return;
}
if (value.isPressed)
{
rb.velocity += new Vector2(0, _jumpspeed);
}
}
void Run()
{
Vector2 _playervelocity = new Vector2(_moveinput.x * _movespeed, rb.velocity.y);
rb.velocity = _playervelocity;
bool _playerHasHorizontalSpeed = Math.Abs(rb.velocity.x) > Mathf.Epsilon;
_animator.SetBool("isRunning", _playerHasHorizontalSpeed);
}
void FlipSprite()
{
bool _playerHasHorizontalSpeed = Math.Abs(rb.velocity.x) > Mathf.Epsilon;
if (_playerHasHorizontalSpeed)
{
transform.localScale = new Vector2(Mathf.Sign(rb.velocity.x), 1f);
}
}
void ClimbLadder()
{
if (!_isTouchingLadder)
{
// Turn off climbing animation if not touching ladder
_animator.SetBool("isClimbing", false);
return;
}
Vector2 _climbvelocity = new Vector2(rb.velocity.x, _moveinput.y * _climbspeed);
rb.velocity = _climbvelocity;
bool _playerIsClimbing = Math.Abs(rb.velocity.y) > Mathf.Epsilon;
_animator.SetBool("isClimbing", _playerIsClimbing);
}
// Trigger detection for ladder
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.layer == LayerMask.NameToLayer("Climbing"))
{
_isTouchingLadder = true;
}
}
private void OnTriggerExit2D(Collider2D other)
{
if (other.gameObject.layer == LayerMask.NameToLayer("Climbing"))
{
_isTouchingLadder = false;
}
}
}