Skip to content

Instantly share code, notes, and snippets.

@JonathanYin
Created July 17, 2017 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonathanYin/5ddf212b26a8797a4990afb90c1c04e3 to your computer and use it in GitHub Desktop.
Save JonathanYin/5ddf212b26a8797a4990afb90c1c04e3 to your computer and use it in GitHub Desktop.
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>());
}
}
}
@JonathanYin
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment