Trigger Scripts

psai for Unity ›› Scripts ››
Parent Previous Next

psai comes with a set of scripts that can be attached to GameObjects in your Unity Scenes, to conveniently place events in your Scene that can either..

  1. trigger Themes
  2. stop the music, or...
  3. force the music to return immdediately to the last Basic Mood

The first public variable of each is script lets you choose one of these three functions.


This is the base class for all scripts that should get synchronized by the PsaiCoreManager. Synchronization fixes the following problem: Imagine two enemy objects, one being very close to the player, and the other enemy far away. Both enemy objects continuosly send events that control the musical intensity in relation to the distance to the Player. The nearer enemy would trigger the music with high intensity, and the enemy far away triggers with low intensity. Without synchronization, the music would jump wildly between these two intensity levels. To fix that, the PsaiCoreManager evaluates all PsaiSynchronizedTriggers in the rate defined by its "Tick" interval, and will filter out concurrent trigger events of lower intensity.

If you find that the provided scripts are not enough, please feel free to implement your own. If you derive from PsaiSynchronizedTrigger you will only need to implement two methods:

1. override EvaluateTriggerCondition() to define if your trigger shall fire or not within this Tick

2. implement CalculateTriggerIntensity() where you return a float value between 0 and 1.0 that reflects the musical intensity.


Add this to an arbitrary GameObject to have a Theme played whenever a Scene has started / a new Level has loaded.


Add this to a GameObject holding a Collider. The script will fire as soon as the collision with the Player occurs. If the Player collider variable has not been assigned, the Script will at runtime look for a GameObject tagged or named as "Player".


Triggers whenever the player steps within the defined trigger range, either one-shot or continuously.


Call the OnSignal() function of this script to fire a one-shot trigger event.


Fires the trigger event as soon as the component is enabled.

For full flexibility, feel free to call the psai API functions directly. The API is very slim and is documented at