-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBomb.cs
44 lines (37 loc) · 1.19 KB
/
Bomb.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
33
34
35
36
37
38
39
40
41
42
43
44
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bomb : MonoBehaviour
{
public float delay;
public float explosionRadius;
public float explosionForce;
public float upModifier;
public LayerMask interactionMask;
public GameObject particalPrefab;
private GameObject particleInstance;
// Start is called before the first frame update
void Start()
{
Invoke(nameof(Explode), delay);
}
void Explode()
{
Collider[] colliders = Physics.OverlapSphere(transform.position, explosionRadius, interactionMask);
foreach (var c in colliders)
{
c.GetComponent<Rigidbody>()
.AddExplosionForce(explosionForce, transform.position, explosionRadius, upModifier, ForceMode.Impulse);
}
particleInstance = Instantiate(particalPrefab, transform.position, Quaternion.identity);
GetComponent<AudioSource>().Play();
GetComponent<Renderer>().enabled = false;
GetComponent<Collider>().enabled = false;
Invoke(nameof(Kill), 5);
}
void Kill()
{
Destroy(particleInstance);
Destroy(gameObject);
}
}