Search Unity

[Solved] Modifying UI Buttons Without Using Inspector

Discussion in 'UGUI & TextMesh Pro' started by slader155, Feb 10, 2015.

  1. slader155

    slader155

    Joined:
    Jun 22, 2014
    Posts:
    5
    Hi everyone,

    I'm trying to change the gameObject that the OnClick in the inspector is using to call a function. The problem is that I'm trying to set it to a certain GameObject that I'm instantiating after a certain amount of seconds. Here is a picture of what I'm trying to change:

    I've pretty much reached my limit trying to figure this one out, please help me!
     
  2. slader155

    slader155

    Joined:
    Jun 22, 2014
    Posts:
    5
    Nevermind, I solved it! :D

    If anyone is wondering, I simply attached this script to the button:
    public GameObject soundButton;

    // Use this for initialization
    void Start () {
    soundButton = GameObject.FindGameObjectWithTag("ButtonSound");
    GetComponent<Button>().onClick.AddListener(() => soundButton.GetComponent<ButtonSound>().Play());
    }
     
  3. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    If you are doing events dynamically that is the only way to do it.

    Events in the editor can only be edited in the editor (or in the editor functions). As such, they are fixed configuration in the project.