Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class BombControl : MonoBehaviour {
- public GameObject explosionPrefab;
- public BoxCollider2D bombBoxCollider;
- private GameObject currentBomb;
- private BoxCollider2D boxCollider;
- private bool noCollider = true;
- void Start () {
- }
- private IEnumerator CreateExplosions (Vector3 direction) {
- for (int i = 1; i < 3; i++) {
- RaycastHit2D hit;
- Physics2D.Raycast (transform.position + new Vector3 (0.0f, 0.5f, 0.0f), direction, out hit, i);
- if (!hit.collider) {
- Instantiate (explosionPrefab, transform.position + (i * direction), explosionPrefab.transform.rotation);
- } else {
- break;
- }
- }
- }
- void Explode(){
- /*GameObject explosion = Instantiate (explosionPrefab, (transform.position), Quaternion.identity)
- as GameObject;*/
- StartCoroutine(CreateExplosions(Vector3.forward));
- StartCoroutine(CreateExplosions(Vector3.right));
- StartCoroutine(CreateExplosions(Vector3.back));
- StartCoroutine(CreateExplosions(Vector3.left));
- Destroy (gameObject);
- }
- //Creates a Collider on the bomb once the players steps off of it
- void OnTriggerExit2D (Collider2D collider) {
- if(noCollider){
- boxCollider = Instantiate(bombBoxCollider, (transform.position), Quaternion.identity)
- as BoxCollider2D;
- boxCollider.transform.parent = transform;
- noCollider = false;
- }
- }
- void Update () {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement