I am trying to deactivate jumping (for the sake of testing) when the player interacts with an object. However, jumping is still working. What is going on?
PlayerMovement Script:
public class CharacterController : MonoBehaviour
{
public static CharacterController Instance {get; private set; }
[SerializeField] private float jumpForce = 500;
private Rigidbody2D playerRb;
private Collider2D playerCollider;
private InputSystem_Actions inputSystemActions;
private void Awake()
{
// Singleton
if (Instance != null && Instance != this)
{
Destroy(gameObject);
}
Instance = this;
// References
playerRb = GetComponent<Rigidbody2D>();
playerCollider = GetComponent<Collider2D>();
// Input system
inputSystemActions = new InputSystem_Actions();
inputSystemActions.Player.Enable();
inputSystemActions.Player.Jump.performed += Jump;
}
private void Jump(InputAction.CallbackContext context)
{
if (playerCollider.IsTouchingLayers(LayerMask.GetMask("Ground", "Interactable"))) //cant do 6, bitmask. 6 is layer 1 and 2
{
playerRb.AddForceY(jumpForce);
}
}
}