1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. Unity 5.6 is now released.
    Dismiss Notice
  3. Check out all the fixes for 5.5 in patch releases 1 & 2.
    Dismiss Notice
  4. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  5. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    Dismiss Notice

Power button

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

  1. ksam2

    ksam2

    Joined:
    Apr 28, 2012
    Posts:
    837
    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++

    Joined:
    Mar 10, 2012
    Posts:
    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

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

    RANDOM++

    Joined:
    Mar 10, 2012
    Posts:
    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

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

    RANDOM++

    Joined:
    Mar 10, 2012
    Posts:
    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 :)