Author Topic: Modify EventTrigger From Script?  (Read 3138 times)

Gaudon

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Modify EventTrigger From Script?
« on: March 18, 2014, 03:18:59 PM »
IGNORE POST I'm the dumbest human on the planet. My interface gameobject was enabled, but I had *temporarily* disabled the Interface.cs script and thus none of the code I was writing was executing. It works perfectly fine. Sigh.

Hey Guys,

I'm having some issues getting buttons to work. I essentially have a Texture component with an attached Box Collider (adjusted to match button size) and UIEvent Trigger.

From my primary Interface.cs script, I would like to take this texture button, and assign it's callbacks to various functions inside Interface.cs.

Inside Interface.cs, I have something that looks like this:

  1. GameObject helpButton;
  2. ...
  3. helpButton = GameObject.Find("HelpButton");
  4. ...
  5. EventDelegate.Add(helpButton.GetComponent<UIEventTrigger>().onClick, ShowHowToPlay);
  6.  

This is with the intention of adding the ShowHowToPlay() function from within Interface.cs to the button's onClick callback.

  1. void ShowHowToPlay() {
  2.   howToPlayWindow.SetActive(true);
  3. }
  4.  

Admittedly, I do not know how to accomplish this, I am piecing things from various sources.. All of which tend to favor the "just drag your component into the event" which isn't flexible enough for things I know I'm going to need.

Is there a way to do this (I assume so), and if so, what have I done wrong?

Thanks!

EDIT: I have been equally as unsuccessful with adding a UIButton component to the texture with a box collider. Although I assume the AddDelegate code would be incorrect for a button.
« Last Edit: March 18, 2014, 03:41:46 PM by Gaudon »