0
\$\begingroup\$

I need a "button" like trigger. The player would walk within the invisible cube that is the trigger, once the player is in the trigger (and only in the trigger) they would be able to press 'e' on their keyboard which will cause the animations to play at once. After the animation plays, the screen fades to black and loads the next scene.

I'm still incredibly new to Unity so a brief summary of the code you provide would be much appreciated! (but not at all demanded!)

Personally I'm a lot more comfortable with C# so if the code can be in that, it would really help. Thank you!

\$\endgroup\$
1
\$\begingroup\$

For the inside trigger and only trigger and nothing but the trigger part you can use OnTriggerStay(Collider) function which is a built-in MonoBehaviour Message handler, and inside this handler check if the player presses the "E" key.

To check if the trigger you're staying in is the one you want, you can give the trigger a tag (or put it on a specific layer, or attach a specific "Activation" component, etc.)

void OnTriggerStay(Collision col)
{
    if(Input.GetKeyDown(KeyCode.E) && col.gameObject.CompareTag("SomeTag"))
    {
        Animator anim = this.gameObject.GetComponent<Animator>();
        anim.Play("SomeAnim");
        DoFade();
    }
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.