Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class BoomBoom : MonoBehaviour
- {
- //How long till the bomb is active after spawning
- ` public float m_PrimeTime = 2;
- //How long has the bomb exsisted
- public double m_PreDetTime;
- //The prefab the actually explodes
- public GameObject Explosion;
- //How much force it takes to explode
- public int Impact_Threshold;
- private void OnCollisionEnter(Collision collision)
- {
- //Has the bomb existed for long enough to be primed? If yes continue
- if (m_PreDetTime >= m_PrimeTime)
- {
- //Is force of impact greater than the Impact_Threshold? If so continue
- if (collision.relativeVelocity.magnitude > Impact_Threshold)
- {
- //Object is created where the bomb is on impact, this creates the explosion before despawning
- GameObject BoomHolder = Instantiate(Explosion, this.transform.position, this.transform.rotation) as GameObject;
- //Destroy the Bomb
- Destroy(this.gameObject);
- //Destory the BoomHolder after 5 Seconds (Make this slightly longer than your clip)
- Destroy(BoomHolder, 5.0f);
- }
- }
- }
- void Update()
- {
- m_PreDetTime += Time.deltaTime;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement