Search Unity

Use game objects as triggers

Discussion in 'Scripting' started by Roldo, May 14, 2019.

  1. Roldo


    Oct 25, 2014
    Hi! Long story short, i need to make a system where a node game object has a so called "trigger object" it is basically any object that should send a "message" to any node its attached to. The message should work as an interrupt that would start a method on the node. I was considering using custom events for it, however i cant do it, because there could be a couple different triggers for different nodes, and i dont want all triggers to trigger the same event. What i want to do is to make only the node, that is referencing the trigger to recieve the "message". I could do it with a bool on the trigger that just sais enabled or disaed and check it from the node, but it eould be pretty inefficient.
    Do you have any ideas for how i could make it work?

    Sorry for my english, im not a native speaker.
  2. ArachnidAnimal


    Mar 3, 2015
    Look at the "ActivateTrigger" class contained in the standard assets.
    (Standard Assets\Utility\ActivateTrigger.cs).
    That is a pattern where the trigger notifies the "listener" that a trigger action has occurred.