Skip to content

Instantly share code, notes, and snippets.

@PrashantUnity
Created August 6, 2022 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PrashantUnity/ec05c12c761dcf5a6c34e791f73ff02f to your computer and use it in GitHub Desktop.
Save PrashantUnity/ec05c12c761dcf5a6c34e791f73ff02f to your computer and use it in GitHub Desktop.
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