-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExplosionManager.cs
More file actions
42 lines (39 loc) · 1.07 KB
/
ExplosionManager.cs
File metadata and controls
42 lines (39 loc) · 1.07 KB
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ExplosionManager : MonoBehaviour
{
public GameObject bullet;
public float power = 10.0f;
public float radius = 5.0f;
public float upforce = 1.0f;
/* void OnCollisionEnter(Collision col)
{
if (col.gameObject.name == "helicopter")
{
Destroy(col.gameObject);
}
}
*/
// Update is called once per frame
void FixedUpdate()
{
if (bullet == enabled)
{
Invoke("Detonate", 5);
}
}
void Detonante()
{
Vector3 explosionPosition = bullet.transform.position;
Collider[] colliders = Physics.OverlapSphere(explosionPosition, radius);
foreach (Collider hit in colliders)
{
Rigidbody rb = hit.GetComponent<Rigidbody>();
if (rb != null)
{
rb.AddExplosionForce(power, explosionPosition, radius, upforce, ForceMode.Impulse);
}
}
}
}