Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class GenCubeExplode : MonoBehaviour
  6. {
  7. public float radius = 1.0F;//Radius of explosion becareful how far apart you set object they can be caught in this explosion
  8. public float power = 10.0F;//power applied to objects hit
  9.  
  10. void Start()
  11. {
  12. Vector3 explosionPos = this.transform.position;//inital position of explosion
  13. Collider[] colliders = Physics.OverlapSphere(explosionPos, radius);//create imaginary sphere to detect what was hit by explosion
  14. foreach (Collider genCube in colliders)
  15. {
  16. if(genCube.tag == "genCube")//if its a genCube apply force and turn on gravity for object
  17. {
  18. Rigidbody rb = genCube.GetComponent<Rigidbody>();
  19.  
  20. if (rb != null)
  21. {
  22. rb.AddExplosionForce(power, explosionPos, radius, 3.0F);
  23. rb.useGravity = true;
  24. }
  25. }
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement