dronkowitz

ItemBalloon.cs

Aug 17th, 2021 (edited)
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 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.             popped = true;
  29.             Destroy(gameObject);
  30.         }
  31.     }
  32. }
  33.  
Add Comment
Please, Sign In to add comment