Advertisement
Guest User

BombControl

a guest
Jul 10th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class BombControl : MonoBehaviour {
  5.  
  6. public GameObject explosionPrefab;
  7. public BoxCollider2D bombBoxCollider;
  8.  
  9. private GameObject currentBomb;
  10. private BoxCollider2D boxCollider;
  11. private bool noCollider = true;
  12.  
  13. void Start () {
  14. }
  15.  
  16. private IEnumerator CreateExplosions (Vector3 direction) {
  17. for (int i = 1; i < 3; i++) {
  18. RaycastHit2D hit;
  19.  
  20. Physics2D.Raycast (transform.position + new Vector3 (0.0f, 0.5f, 0.0f), direction, out hit, i);
  21.  
  22. if (!hit.collider) {
  23. Instantiate (explosionPrefab, transform.position + (i * direction), explosionPrefab.transform.rotation);
  24. } else {
  25. break;
  26. }
  27. }
  28. }
  29.  
  30. void Explode(){
  31. /*GameObject explosion = Instantiate (explosionPrefab, (transform.position), Quaternion.identity)
  32. as GameObject;*/
  33. StartCoroutine(CreateExplosions(Vector3.forward));
  34. StartCoroutine(CreateExplosions(Vector3.right));
  35. StartCoroutine(CreateExplosions(Vector3.back));
  36. StartCoroutine(CreateExplosions(Vector3.left));
  37.  
  38. Destroy (gameObject);
  39. }
  40.  
  41. //Creates a Collider on the bomb once the players steps off of it
  42. void OnTriggerExit2D (Collider2D collider) {
  43. if(noCollider){
  44. boxCollider = Instantiate(bombBoxCollider, (transform.position), Quaternion.identity)
  45. as BoxCollider2D;
  46. boxCollider.transform.parent = transform;
  47. noCollider = false;
  48. }
  49. }
  50.  
  51. void Update () {
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement