Skip to content

Instantly share code, notes, and snippets.

Created August 6, 2022 23:01
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment