Advertisement
dronkowitz

Crate.cs

Feb 27th, 2021 (edited)
1,013
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  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<UltimatePlayerMovement>())
  23.         {
  24.             DestroyCrate();
  25.         }
  26.     }
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement