-
Notifications
You must be signed in to change notification settings - Fork 5
/
Crate.cs
32 lines (27 loc) · 978 Bytes
/
Crate.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using UnityEngine;
namespace Section.MiscUnity.Destructable
{
public class Crate : MonoBehaviour
{
public GameObject fracturedCrate;
public GameObject explostionEffect;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
Instantiate(explostionEffect, transform.position, Quaternion.identity);
GameObject fracturedCrateObj = Instantiate(fracturedCrate, transform.position, Quaternion.identity);
Rigidbody[] allRigidBodies = fracturedCrateObj.GetComponentsInChildren<Rigidbody>();
if (allRigidBodies.Length > 0)
{
foreach (var body in allRigidBodies)
{
body.AddExplosionForce(500, transform.position, 1);
}
}
Destroy(this.gameObject);
}
}
}
}