Advertisement
GoodNoodle

WindManager

Sep 17th, 2023 (edited)
1,084
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.92 KB | None | 0 0
  1.  
  2. using System.Collections;
  3. using UnityEngine;
  4.  
  5. public class WindMaker : MonoBehaviour
  6. {
  7.  
  8.     public float waitTime;
  9.     public float delayTime;
  10.  
  11.     public float speed;
  12.  
  13.     [SerializeField] public PlayerController player, buddy;
  14.     public bool isInTrigger;
  15.     public bool windBlowing;
  16.  
  17.     public GameObject wind;
  18.  
  19.     // Start is called before the first frame update
  20.     void Start()
  21.     {
  22.        
  23.  
  24.     }
  25.  
  26.     // Update is called once per frame
  27.     void FixedUpdate()
  28.     {
  29.  
  30.         delayTime -= Time.deltaTime;
  31.  
  32.        
  33.  
  34.         if (waitTime <= 0 )
  35.         {
  36.             StartCoroutine(Restart());
  37.         }
  38.  
  39.         if (delayTime <= 0)
  40.         {
  41.             StartCoroutine(Delay());
  42.  
  43.         }
  44.  
  45.         if (isInTrigger == true)
  46.         {
  47.             StartCoroutine(PushDirection());
  48.         }
  49.     }
  50.  
  51.     private void OnTriggerEnter2D(Collider2D other)
  52.     {
  53.         if (other.tag == "Player")
  54.         {
  55.             isInTrigger = true;
  56.         }
  57.  
  58.  
  59.         if (other.tag == "Buddy")
  60.         {
  61.             isInTrigger = true;
  62.         }
  63.     }
  64.     private void OnTriggerExit2D(Collider2D other)
  65.     {
  66.         if (other.tag == "Player")
  67.         {
  68.             isInTrigger = false;
  69.  
  70.         }
  71.  
  72.         if (other.tag == "Buddy")
  73.         {
  74.             isInTrigger = false;
  75.         }
  76.     }
  77.  
  78.     public IEnumerator PushDirection()
  79.     {
  80.         yield return new WaitForSeconds(waitTime);
  81.         Vector2 pos = player.theRb.position;
  82.         player.theRb.position += Vector2.down * speed * Time.deltaTime;
  83.         player.theRb.MovePosition(pos);
  84.  
  85.  
  86.     }
  87.  
  88.     public IEnumerator Delay()
  89.     {
  90.         yield return new WaitForSeconds(delayTime);
  91.         wind.SetActive(false);
  92.  
  93.         windBlowing = false;
  94.     }
  95.  
  96.     public IEnumerator Restart()
  97.     {
  98.         yield return new WaitForSeconds(waitTime);
  99.         wind.SetActive(true);
  100.         windBlowing = true;
  101.     }
  102.  
  103. }
  104.  
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement