Skip to main content
Code cleanup - talked about Stay but used Enter, slow version of tag check
Source Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401

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

Remember that you have to give the trigger GameObject a Tag in order toTo check if the trigger youryou'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 OnTriggerEnterOnTriggerStay(Collision col)
{
    if(colInput.gameObjectGetKeyDown(KeyCode.tag == "SomeTag"E) && Inputcol.GetKey(KeyCodegameObject.ECompareTag("SomeTag"))
    {
        Animator anim;
        anim = this.gameObject.GetComponent<Animator>();
        anim.Play("SomeAnim");
        DoFade();
    }
}

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

Remember that you have to give the trigger GameObject a Tag in order to check if the trigger your staying in is the one you want.

void OnTriggerEnter(Collision col)
{
    if(col.gameObject.tag == "SomeTag" && Input.GetKey(KeyCode.E))
    {
        Animator anim;
        anim = this.gameObject.GetComponent<Animator>();
        anim.Play("SomeAnim");
        DoFade();
    }
}

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();
    }
}
Grammar and formating
Source Link
Engineer
  • 30.4k
  • 4
  • 76
  • 124

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

Remember that you have to give the trigger GameObject a Tag in order to check if the trigger your staying in is the one you want.

void OnTriggerEnter(Collision col)  
{
    if(col.gameObject.tag == "SomeTag" && Input.GetKey(KeyCode.E))
    {
        Animator anim;
        anim = this.gameObject.GetComponent<Animator>();
        anim.Play("SomeAnim");
        DoFade();
    }
}

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

Remember that you have to give the trigger GameObject a Tag in order to check if the trigger your staying in is the one you want.

void OnTriggerEnter(Collision col) {
    if(col.gameObject.tag == "SomeTag" && Input.GetKey(KeyCode.E)) {
        Animator anim;
        anim = this.gameObject.GetComponent<Animator>();
        anim.Play("SomeAnim");
        DoFade();
    }
}

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

Remember that you have to give the trigger GameObject a Tag in order to check if the trigger your staying in is the one you want.

void OnTriggerEnter(Collision col) 
{
    if(col.gameObject.tag == "SomeTag" && Input.GetKey(KeyCode.E))
    {
        Animator anim;
        anim = this.gameObject.GetComponent<Animator>();
        anim.Play("SomeAnim");
        DoFade();
    }
}

forFor the inside trigger and only trigger and nothing but the trigger part you can use OnTriggerStay(Collider)OnTriggerStay(Collider) function which is a built-in UnityEvent and inside this event check if the player hitspresses the "E" key. remember

Remember that you have to give the trigger GameObject a Tag in order to check if the trigger your staying in is the one you want.

    void OnTriggerEnter(Collision col)
  {
    if(col.gameObject.tag == "SomeTag" && Input.GetKey(KeyCode.E))
    {
        Animator anim;
        anim = this.gameObject.GetComponent<Animator>();
        anim.Play("SomeAnim");
        DoFade();
    }
}

for the inside trigger and only trigger and nothing but the trigger part you can use OnTriggerStay(Collider) function which is a built-in UnityEvent and inside this event check if the player hits "E". remember that you have to give the trigger GameObject a Tag in order to check if the trigger your staying in is the one you want.

    void OnTriggerEnter(Collision col)
 {
    if(col.gameObject.tag == "SomeTag" && Input.GetKey(KeyCode.E))
    {
        Animator anim;
        anim = this.gameObject.GetComponent<Animator>();
        anim.Play("SomeAnim");
        DoFade();
    }
}

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

Remember that you have to give the trigger GameObject a Tag in order to check if the trigger your staying in is the one you want.

void OnTriggerEnter(Collision col) {
    if(col.gameObject.tag == "SomeTag" && Input.GetKey(KeyCode.E)) {
        Animator anim;
        anim = this.gameObject.GetComponent<Animator>();
        anim.Play("SomeAnim");
        DoFade();
    }
}
Source Link
Loading