Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Trigger Events

Discussion in 'Scripting' started by jack-jack, Dec 2, 2007.

  1. jack-jack

    jack-jack

    Joined:
    Oct 11, 2007
    Posts:
    9
    Hello

    Just wondering if I am not understanding things properly - but do trigger events only fire off once?

    I've modified the animation in the posted example www.otee.dk/joe/trigger.zip so that cube passes back through the collider which is a trigger.

    I also added the following
    Code (csharp):
    1.  
    2. function OnTriggerEnter (col : Collider) {
    3.     print("Entering trigger");
    4. }
    5.  
    6. function OnTriggerExit (col : Collider) {
    7.     print("Exit trigger");
    8. }
    9.  
    10.  
    so that I could see when events were firing. The OnTriggerEnter event only happens once ( or appears to), am I misinterpreting the way these events should work as this appears to be the main reason why much of my current game is not working - I'm relying on the trigger events to fire off more than once.


    Thanks
    Jack
     
  2. HJPuhlmann

    HJPuhlmann

    Joined:
    Oct 18, 2007
    Posts:
    47
    Hello,

    if you need more then one trigger event try:

    OnTriggerStay

    Heinz
     
  3. jack-jack

    jack-jack

    Joined:
    Oct 11, 2007
    Posts:
    9
    Hello HJPuhlmann

    I've modified the script as such

    Code (csharp):
    1.  
    2. function OnTriggerEnter (col : Collider) {
    3.     print("Entering trigger");
    4. }
    5.  
    6. function OnTriggerExit (col : Collider) {
    7.     print("Exit trigger");
    8. }
    9.  
    10. function OnTriggerStay (col : Collider) {
    11.     print("Entering trigger (stay)");
    12. }
    13.  
    and set the Animation wrap mode to ping-pong, but the trigger events still appear once in the console log?
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Turn off "collapse" in the console. Triggers would be pretty useless if they only ever worked once. ;)

    --Eric
     
  5. jack-jack

    jack-jack

    Joined:
    Oct 11, 2007
    Posts:
    9
    Doh! Thanks Eric - the mistakes one makes at 3 in the morning. This means the bug in my game is somewhere else!
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Don't feel bad...I think most people get bitten by this (I know I did). Probably would be better if it was off by default....

    --Eric