dronkowitz

Crate.cs

Feb 27th, 2021
911
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Crate : MonoBehaviour
  6. {
  7.     public GameObject[] spawnable = new GameObject[0];
  8.     public AudioClip breakSound;
  9.     public void DestroyCrate()
  10.     {
  11.         int num = Random.Range(0, spawnable.Length);
  12.         Instantiate(spawnable[num], transform.position, transform.rotation);
  13.  
  14.         GameObject source = Resources.Load<GameObject>("Audio Object");
  15.         source = Instantiate(source, transform.position, transform.rotation);
  16.         source.GetComponent<AudioObject>().Setup(breakSound, transform);
  17.         Destroy(gameObject);//Replace with broken crate model
  18.     }
  19.  
  20.     private void OnCollisionEnter(Collision collision)
  21.     {
  22.         if (collision.gameObject.GetComponent<PlayerMovement>())
  23.         {
  24.             DestroyCrate();
  25.         }
  26.     }
  27. }
  28.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×