Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2021
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class FatBird : MonoBehaviour
  6. {
  7.     public float jumpForse;
  8.     public float waitSeconds;
  9.  
  10.     public Transform groundCheck;
  11.     public LayerMask whatIsGround;
  12.     private bool isGrounded;
  13.     public float checkRadius;
  14.  
  15.     public ParticleSystem dust;
  16.  
  17.     private Rigidbody2D rb;
  18.  
  19.     void Start()
  20.     {
  21.         rb = GetComponent<Rigidbody2D>();
  22.         StartCoroutine(UpdateRoutine());
  23.     }
  24.  
  25.     IEnumerator UpdateRoutine()
  26.     {
  27.         while (true)
  28.         {
  29.             JumpBird();
  30.             yield return new WaitForSeconds(waitSeconds * 1f);
  31.         }
  32.     }
  33.  
  34.     private void Update()
  35.     {
  36.         if (isGrounded == false)
  37.         {
  38.             CreateDust();
  39.         }
  40.     }
  41.  
  42.     private void FixedUpdate()
  43.     {
  44.         isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
  45.     }
  46.  
  47.  
  48.     void JumpBird()
  49.     {
  50.         rb.velocity = Vector2.up * jumpForse;
  51.     }
  52.  
  53.     void CreateDust()
  54.     {
  55.         dust.Play();
  56.     }
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement