using UnityEngine; using System.Collections; public class Revulsion_Field : MonoBehaviour{ [Header("This script will create a propulsion field that will launch any object that enters it's area in the direction of the propulsor(usually green arrow)")] public int strength; [Header("This option will instead create a repulsion field, that will repell any incoming item immediatelly based on the incoming angle")] public bool Angular_Revulsion; void OnTriggerEnter(Collider col){ if(col.GetComponent()){ if(Angular_Revulsion){ Vector3 Angle = (col.transform.position - transform.position)/2; col.gameObject.GetComponent().AddForce(Angle*strength); } else{ col.GetComponent().AddForce(this.transform.up * strength); } } } void OnTriggerStay(Collider other){ if (other.gameObject.GetComponent()){ if(Angular_Revulsion){ Vector3 Angle = (other.transform.position - transform.position)/2; other.gameObject.GetComponent().AddForce(Angle*strength); } else{ other.GetComponent().AddForce(this.transform.up * strength); } } } }