Change a variable value through the event trigger component of another object

I have a object with this script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Targets : MonoBehaviour {

    public GameController gamecontroller;

    // Use this for initialization
    void Start () {

    }
   
    // Update is called once per frame
    void Update () {
       
    }

    void enableInteraction(){
        gamecontroller.interaction = true;
    }
}

And I have included a Event Trigger component in this same object that I intend to use to call the enableInteraction() but its not showing the in the list options of this component. How can I call this function using the Event Trigger component?

Thanks in advance.

If you don’t specify public, it’s automatically private.

Change it to public void enableInteraction()

1 Like

Great! Thanks.

One more doubt related to the Event Trigger: How can I check the trigger only once?

Depends on how it’s triggering. You could just do a simple bool for once you check it the first time, then you set the bool to true and check that bool to see if it’s true or not.

Or, if it’s a button or a collider trigger, you might just be able to turn off the component. Just depends.

1 Like

I got it.

Thank you. You really helped me.