Advertisement
OldBeliver

Jump

Jul 3rd, 2022
1,032
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.InputSystem;
  5.  
  6. [RequireComponent(typeof(PlayerInput))]
  7.  
  8. public class Jump : MonoBehaviour
  9. {
  10.     [SerializeField] private float _jumpForce;
  11.  
  12.     private bool _isGrounded;
  13.  
  14.     public void OnJump()
  15.     {
  16.         if (_isGrounded)
  17.         {
  18.             Debug.Log($"Jump");
  19.         }
  20.  
  21.     }
  22.  
  23.     private void OnCollisionEnter2D(Collision2D collision)
  24.     {
  25.         if (collision.collider.TryGetComponent(out Ground ground))
  26.         {
  27.             _isGrounded = true;
  28.         }
  29.     }    
  30.  
  31.     private void OnCollisionExit2D(Collision2D collision)
  32.     {
  33.         if (collision.collider.TryGetComponent(out Ground ground))
  34.         {
  35.             _isGrounded = false;
  36.         }
  37.     }
  38. }
  39.  
Advertisement
RAW Paste Data Copied
Advertisement