Custom trigger (triggers one actionlist when entering and another when exiting)

Note: Use this as an example for running actionlist asset through script, or as a base for more complex triggers (without scripting you can achieve this effect by placing two AC trigger scripts on the same object). This script triggers an actionlist asset when an object enters the collider trigger and triggers another when the object exits. This is useful for camera switching, opening and closing doors; generally actions that need to be reverted, or anything else you can think of. Just drop the script onto an object with a collider set as IsTrigger (check it in the object's inspector). Alternatively, you can choose a game object, scroll down through the inspector and hit the "Add Component" button, type the script name in the search bar that appears and then click the scripts name in the list. You can select the tag the Trigger will affect, Default is 'Player'. There are two slots for Actionlist Assets, one to be triggered on enter and one for on exit.

There are two ways to create the script:

1 Create a blank text file, paste the code, then rename the file to the name of the class and change the extension to .cs (CustomTrigger3D.cs or CustomTrigger2D.cs) or

2. Create a script inside unity in the library tab named as mentioned before, then just replace the whole text in the file. Do make sure the names are correct or Unity won't allow you to attach the script to any object.

Like most scripts it needs to be dropped/attached onto a game object to work (in this case a blank trigger). If you need to know more about how to make a blank trigger you can check this 3 minute video from the Unity tutorials section (you only need to watch the first 30 seconds though).

This is the 3D version:

using UnityEngine; using AC; public class CustomTrigger3D : MonoBehaviour {        [SerializeField] //used to expose private variables to the inspector [Tooltip("Name of the tag the collider will respond to. All others will be ignored.")] //used to create a tooltip private string TagToDetect = "Player"; //default tag is 'Player' [SerializeField] [Tooltip("Actionlist Asset to activate when the right object enters the collider.")] private ActionListAsset toDoOnEnter; //Action list to do on enter [SerializeField] [Tooltip("Actionlist Asset to activate when the right object exits the collider.")] private ActionListAsset toDoOnExit; //Action list to do on exit //remove the collider variables if you don't care who enters the trigger. //If you do remove them, also remove the if conditions. and the 3 TagToDetect declaration lines. void OnTriggerEnter(Collider other) {            if (other.tag == TagToDetect) {                if (toDoOnEnter != null) {                    AdvGame.RunActionListAsset(toDoOnEnter); }            }         }         void OnTriggerExit(Collider other) {            if (other.tag == TagToDetect) {                if (toDoOnExit != null) {                    AdvGame.RunActionListAsset(toDoOnExit); }            }         }     } This is the 2D version (just use 2D colliders instead): using UnityEngine; using AC; public class CustomTrigger2D : MonoBehaviour {        [SerializeField] //used to expose private variables to the inspector [Tooltip("Name of the tag the collider will respond to. All others will be ignored.")] //used to create a tooltip private string TagToDetect = "Player"; //default tag is 'Player' [SerializeField] [Tooltip("Actionlist Asset to activate when the right object enters the collider.")] private ActionListAsset toDoOnEnter; //Action list to do on enter [SerializeField] [Tooltip("Actionlist Asset to activate when the right object exits the collider.")] private ActionListAsset toDoOnExit; //Action list to do on exit //remove the collider variables if you don't care who enters the trigger. //If you do remove them, also remove the if conditions. and the 3 TagToDetect declaration lines. void OnTriggerEnter2D(Collider2D other) {            if (other.tag == TagToDetect) {                if (toDoOnEnter != null) {                    AdvGame.RunActionListAsset(toDoOnEnter); }            }         }         void OnTriggerExit2D(Collider2D other) {            if (other.tag == TagToDetect) {                if (toDoOnExit != null) {                    AdvGame.RunActionListAsset(toDoOnExit); }            }         }     }

-Provided by Alverik-