Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement