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 ExploderForceRange : MonoBehaviour | |
{ | |
public float radius = 5f; | |
public float force = 70f; | |
private void OnTriggerEnter(Collider other) | |
{ | |
// get all surrounding objects collider with in radius range | |
var allObject = Physics.OverlapSphere(transform.position, radius); | |
foreach (var item in allObject) | |
{ | |
Rigidbody rb = item.GetComponent<Rigidbody>(); | |
if (rb != null) | |
{ | |
// make sure that position placeholder of the below function is position of | |
// the object on which script is attached | |
rb.AddExplosionForce(force, transform.position, radius); | |
// or else weird stuff will happen | |
//like this live videos https://youtu.be/6F3AhLpNwec | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment