Power button

Discussion in 'Scripting' started by ksam2, Apr 28, 2012.

  1. ksam2

    ksam2

    Member

    Joined:
    Apr 28, 2012
    Messages:
    263
    hi again again and again. I'm just getting crazy :mad: I am new in unity please help me

    I have a Power button in my game and I want when I getting close to button and press E one animation get play
    but I have no Idea how can I do that, I've search for that but can't find anything

    my mean is something like trigger in UDK
     
  2. RANDOM++

    RANDOM++

    New Member

    Joined:
    Mar 10, 2012
    Messages:
    68
    There are trigger functions in Unity so do a search on (OnTriggerEnter or OnTriggerExit) and I'm sure things will get a bit more clear.
     
  3. ksam2

    ksam2

    Member

    Joined:
    Apr 28, 2012
    Messages:
    263
    thanks. I've seen that but I don't know how it works
     
  4. RANDOM++

    RANDOM++

    New Member

    Joined:
    Mar 10, 2012
    Messages:
    68
    If you have a game object with a meshcollider attached to it, you can set a property 'is trigger' to true inside the inspector.

    Inside your script you can then check with the OnTriggerEnter function if some 'other' collider has enterered the trigger, and if so, perform any desired action.

    If you like to know more, either read some more about it or wait till someone else comes in and can give you more details on this because I'm a starter with Unity myself :) However, the function itself is pretty easy to understand.

    Oh btw, the 'other' collider is if I'm correct a special case, so you don't have to assign a specific collider in the script in order for the trigger to work, it will get triggered by any other collider that collides with it.
     
    Last edited: Apr 28, 2012
  5. ksam2

    ksam2

    Member

    Joined:
    Apr 28, 2012
    Messages:
    263
    OMG. that was a big help thanks a lot a real lot :D thanks thanks
     
  6. RANDOM++

    RANDOM++

    New Member

    Joined:
    Mar 10, 2012
    Messages:
    68
    Good luck with it and if you have any problems just post it here, I always like to know what went wrong/good and if I can help I will :)