Created
April 8, 2019 23:37
-
-
Save DB-009/7ff3e2a06be18fd670e2f761ee8334be 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 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