Trying to make a button interactable

Hello,

I’ve search the forums and found similar topics but haven’t found on the helps with this specific issue. I am trying to get a button to be interactable once the player comes into contact with a collider (set to a trigger)
Below is the code I have:

[RequireComponent(typeof(Button))]
public class SpellBook : MonoBehaviour
{

    public Button disarm;
    public Sprite blockA;
    public bool interactable;
    public GameObject trigA;

    private int counter = 0;
    // public event TriggerEventDelegate triggerEvent;
    // Start is called before the first frame update
    void Start()
    {
        disarm = GetComponent<Button>();
        disarm.interactable = false;
        //disarm.Sprite.enabled = false;
    }

    public void OnMouseDown()
    {
        DestroyObject(GameObject.FindGameObjectWithTag("Trap"));
    }

    public void OnTriggerEnter()
    {
        //disarm = GameObject.FindGameObjectWithTag("Prop");
        disarm.interactable = !disarm.interactable;
    }
 }

I have trouble getting this to work myself before, might be a bug. I’m not sure how to fix it, but a work around could be to use a sprite with a collider and a button.

@fafase I am fairly certain it is called. I have it set as being called on runtime on the inspector for the button. I have the collider on the object the player should be interacting with to unlock the ability to use that button for one of their abilities and the trigger button is checked on the collider. I will post an image of both inspectors when I get home from work in about an hour and half in case I missed something.


ok, it worked in this one but not my direct reply…well here are pictures if anyone can help or let me know what i did wrong that would be awesome.

The object that enters the collider must have a rigidbody.

Rigidbody will only work with OnTriggerEnter while Rigidbody2D will only work with OnTriggerEnter2D.

@rdmartyr7 I think you need to assign this script to object which has trigger collider.