Advertisement
Znimatorr

BirbContoller

May 27th, 2022
668
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class BirbController : MonoBehaviour
  6. {
  7.    // bool canJump = true;
  8.     float lastTime;
  9.     bool _isDead;
  10.  
  11.     public bool IsDead
  12.     {
  13.         get
  14.         {
  15.             return _isDead;
  16.         }
  17.         set
  18.         {
  19.             _isDead = value;
  20.             Destroy(this.gameObject);
  21.             GameManager.RestartGame();
  22.         }
  23.     }
  24.  
  25.     Rigidbody2D rb2D;
  26.     void Start()
  27.     {
  28.         lastTime = Time.time - 0.25f;
  29.         rb2D = gameObject.GetComponent<Rigidbody2D>();
  30.     }
  31.  
  32.    
  33.     void Update()
  34.     {
  35.         HandleMovement();
  36.     }
  37.  
  38.     void HandleMovement()
  39.     {
  40.         if (Input.GetKeyDown(KeyCode.Space) && (Time.time - lastTime >= 0.25f))
  41.         {
  42.             lastTime = Time.time;
  43.             Debug.Log("Jump");
  44.             rb2D.velocity = Vector2.zero;
  45.             rb2D.AddForce(Vector2.up * 250);      
  46.         }
  47.     }
  48. }
  49.  
Advertisement
RAW Paste Data Copied
Advertisement