Created
July 17, 2017 16:18
-
-
Save JonathanYin/5ddf212b26a8797a4990afb90c1c04e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class Bomb : MonoBehaviour | |
{ | |
//a holder for our Animator | |
Animator anim; | |
//a public float for the explosion radius | |
public float explodeRadius = 1f; | |
private GameObject bomb; | |
GameObject objToSpawn; | |
// Use this for initialization | |
public Collider2D[] colliders; | |
void Start() | |
{ | |
anim = GetComponent<Animator>(); | |
bomb = GameObject.Find("bomb"); | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
//code no worky? | |
if (anim.GetCurrentAnimatorStateInfo(0).IsName("bombdead")) | |
{ | |
Vector3 v1 = new Vector3(0, 0, 0); //changes the location of the actual explosion (destroying of colliders) and visual | |
//destroy all the objects in a radius unless they are tagged Player or hand | |
//Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position + v1, explodeRadius); | |
colliders = Physics2D.OverlapCircleAll(transform.position + v1, explodeRadius); | |
//Debug.Log(colliders.Length); | |
foreach (Collider2D col in colliders) | |
{ | |
//Collider2D temp = col; | |
if (col.tag != "Player1" && col.tag != "hand" && col.tag != "navbar" && col.tag != "Player2" && col.tag != "Immune") | |
{ | |
col.gameObject.SetActive(false); | |
} | |
} | |
//Destroy(this.gameObject); | |
//Destroy(GetComponent<Collider2D>()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script allows the bomb objects in my game to destroy the pencilline and platforms on which the players run, but do not destroy the players.