4.6 Canvas UI Button Custom Script Function not showing in OnClick Inspector Dropdown

I am just leaning Unity, and upgrading an older database login script that used OnGUI before, to use the 4.6 Canvas elements instead.

I am looking to have the OnClick of the UI Button call the function void ClickLoginButton() in the custom script titled LoginMenu

the OnClick box in the inspector of the UI Button shows the name of my custom script, but doesn’t list any functions

(sorry just saw to use the developer preview forum for this)

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System;

public class LoginMenu : MonoBehaviour {

    private string loginURL = "http://xxx.xxx.xxx.xxx/login.php";

    public static string username = "";
    private string password = "";
    private string label = "";


    void ClickLoginButton(){
        InputField username = GameObject.Find("usernameInput").GetComponent<InputField>();
        string usernameSend = username.value;
        InputField password =  GameObject.Find("passwordInput").GetComponent<InputField>();
        string passwordSend = password.value;
        StartCoroutine(HandleLogin(usernameSend, passwordSend));
    }

    IEnumerator HandleLogin(string username, string password){

        string loginURL = this.loginURL + "?username=" + username + "&password=" + password;
        WWW loginReader = new WWW (loginURL);
        yield return loginReader;

        if(loginReader.error != null) {
            label = "Error Connecting to Database Server.";
        } else {
            if(loginReader.text == "success"){
                label = "Successfully logged in.";
                Application.LoadLevel("Lobby");
            } else {
                label = "Invalid Username or Password.";
        }
        }
    }
}

If you dont specify that a method is public its automatically assumed that its private (the same happens with properties) and a method in order to be showed to the event in must fullfill 3 states.
It must be public,
it must return void
and it must recieve zero or one parameter.

You should change void ClickLoginButton() for public void ClickLoginButton() and that should work :slight_smile:

other option would be you call the Events from the Code and add it to the public LoginMenu

Thanks, that was what I was missing.

Line endings could also be an issue. Could happen when you’ve just made your script.
Just something I ran into