Skip to content

Instantly share code, notes, and snippets.

@DB-009
Created April 8, 2019 23:37
Show Gist options
  • Save DB-009/7ff3e2a06be18fd670e2f761ee8334be to your computer and use it in GitHub Desktop.
Save DB-009/7ff3e2a06be18fd670e2f761ee8334be to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GenCubeExplode : MonoBehaviour
{
public float radius = 1.0F;//Radius of explosion becareful how far apart you set object they can be caught in this explosion
public float power = 10.0F;//power applied to objects hit
void Start()
{
Vector3 explosionPos = this.transform.position;//inital position of explosion
Collider[] colliders = Physics.OverlapSphere(explosionPos, radius);//create imaginary sphere to detect what was hit by explosion
foreach (Collider genCube in colliders)
{
if(genCube.tag == "genCube")//if its a genCube apply force and turn on gravity for object
{
Rigidbody rb = genCube.GetComponent<Rigidbody>();
if (rb != null)
{
rb.AddExplosionForce(power, explosionPos, radius, 3.0F);
rb.useGravity = true;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment