Advertisement
dronkowitz

ItemBallon.cs

Apr 14th, 2022
966
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class ItemBalloon : MonoBehaviour
  6. {
  7.    
  8.     public GameObject[] pickables;
  9.     public bool popped = false;
  10.     // Start is called before the first frame update
  11.     void Start()
  12.     {
  13.        
  14.     }
  15.  
  16.     // Update is called once per frame
  17.     void Update()
  18.     {
  19.        
  20.     }
  21.     private void OnTriggerEnter(Collider other)
  22.     {
  23.         if (other.gameObject.CompareTag("Player") && popped == false)
  24.         {
  25.             int pick = Random.Range(0, pickables.Length);
  26.             Instantiate(pickables[pick], other.transform.position,Quaternion.identity);
  27.             GetComponent<AudioSource>().Play();
  28.             FindObjectOfType<HUD>().AddPower(1);
  29.             popped = true;
  30.             Destroy(gameObject);
  31.         }
  32.     }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement