-
Notifications
You must be signed in to change notification settings - Fork 0
/
BombFragment.cs
43 lines (35 loc) · 1.04 KB
/
BombFragment.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
using UnityEngine;
using System.Collections;
public class BombFragment : MonoBehaviour
{
public float speed = 5.0f; // The speed at which this bomb fragment is propelled away from the initial explosion
public GameObject explosion; // The explosion prefab to be instantiated when this bomb fragment hits something
// Use this for initialization
void Start()
{
transform.Rotate(Random.Range(-180, 180), Random.Range(-180, 180), Random.Range(-180, 180));
}
// Update is called once per frame
void FixedUpdate()
{
transform.Translate(0, 0, speed * Time.deltaTime);
}
void OnCollisionEnter(Collision col)
{
// Make the projectile explode
if (col.collider.gameObject.GetComponent<BombFragment>() == null) // Explode only if the collision is not with another bombfragment
{
Explode(col.contacts[0].point);
}
}
void Explode(Vector3 position)
{
// Instantiate the explosion
if (explosion != null)
{
Instantiate(explosion, position, Quaternion.identity);
}
// Destroy this projectile
Destroy(gameObject);
}
}