Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using UnityEngine;
- public class WindMaker : MonoBehaviour
- {
- public float waitTime;
- public float delayTime;
- public float speed;
- [SerializeField] public PlayerController player, buddy;
- public bool isInTrigger;
- public bool windBlowing;
- public GameObject wind;
- // Start is called before the first frame update
- void Start()
- {
- }
- // Update is called once per frame
- void FixedUpdate()
- {
- delayTime -= Time.deltaTime;
- if (waitTime <= 0 )
- {
- StartCoroutine(Restart());
- }
- if (delayTime <= 0)
- {
- StartCoroutine(Delay());
- }
- if (isInTrigger == true)
- {
- StartCoroutine(PushDirection());
- }
- }
- private void OnTriggerEnter2D(Collider2D other)
- {
- if (other.tag == "Player")
- {
- isInTrigger = true;
- }
- if (other.tag == "Buddy")
- {
- isInTrigger = true;
- }
- }
- private void OnTriggerExit2D(Collider2D other)
- {
- if (other.tag == "Player")
- {
- isInTrigger = false;
- }
- if (other.tag == "Buddy")
- {
- isInTrigger = false;
- }
- }
- public IEnumerator PushDirection()
- {
- yield return new WaitForSeconds(waitTime);
- Vector2 pos = player.theRb.position;
- player.theRb.position += Vector2.down * speed * Time.deltaTime;
- player.theRb.MovePosition(pos);
- }
- public IEnumerator Delay()
- {
- yield return new WaitForSeconds(delayTime);
- wind.SetActive(false);
- windBlowing = false;
- }
- public IEnumerator Restart()
- {
- yield return new WaitForSeconds(waitTime);
- wind.SetActive(true);
- windBlowing = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement