/* This file is part of the "Simple Waypoint System" project by Rebound Games. * You are only allowed to use these resources if you've bought them from the Unity Asset Store. * You shall not license, sublicense, sell, resell, transfer, assign, distribute or * otherwise make available to any third party the Service or the Content. */ using UnityEngine; using UnityEngine.Events; #if UNITY_5_5_OR_NEWER using UnityEngine.AI; #endif namespace SWS { /// /// Can be placed on game objects with colliders to trigger movement script actions. /// public class EventCollisionTrigger : MonoBehaviour { /// /// Checkbox to toggle actions on trigger. /// public bool onTrigger = true; /// /// Checkbox to toggle actions on collision. /// public bool onCollision = true; /// /// Unity Events invoked when colliding. /// public UnityEvent myEvent; void OnTriggerEnter(Collider other) { if (!onTrigger) return; //do something here directly, //or assign event methods in the inspector myEvent.Invoke(); } void OnCollisionEnter(Collision other) { if (!onCollision) return; //do something here directly, //or assign event methods in the inspector myEvent.Invoke(); } /// /// Applies an explosion force to the colliding object. /// public void ApplyForce(int power) { Vector3 position = transform.position; float radius = 5f; Collider[] colliders = Physics.OverlapSphere(position, radius); foreach (Collider hit in colliders) { navMove move = hit.GetComponent(); if (move != null) { move.Stop(); hit.GetComponent().enabled = false; hit.isTrigger = false; } Rigidbody rb = hit.GetComponent(); if (rb != null) rb.AddExplosionForce(power, position, radius, 100.0F); } } } }