Adventure Creator Wikia
Advertisement

Note: This is a custom trigger script to use alongside Adventure Creator. It triggers an actionlist when the object enters the collider and triggers another when the object exits. This is useful for camera switching, opening and closing doors, etc. Just drop the script onto an object with a collider set as IsTrigger (check it in the object's inspector). 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, the 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.

This is the 3D version:

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):

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-

Advertisement