Advertisement
dimon-torchila

Untitled

May 22nd, 2022
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Coin : Bonus
  6. {
  7.     protected bool _isTriggered = false;
  8.     void Awake() {
  9.         _spawnY = 1.5f;
  10.         StartCoroutine(Anim());
  11.     }
  12.     private void OnTriggerEnter(Collider other)
  13.     {
  14.         if (other.name == "Player") {
  15.             _isTriggered = true;
  16.             Inventory inventory = other.GetComponent<Inventory>();
  17.             inventory.ChangeCash(1);
  18.         }
  19.     }
  20.  
  21.     private IEnumerator Anim()
  22.     {
  23.         while (!_isTriggered)
  24.         {
  25.             yield return new WaitForSeconds(1f);
  26.         }
  27.         gameObject.transform.GetChild(0).gameObject.GetComponent<Animation>().Play();
  28.         yield return new WaitForSeconds(1f);
  29.         Destroy(gameObject);
  30.     }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement