Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

So simple but yet does nothing

Discussion in 'Getting Started' started by Shadowing, Jan 31, 2015.

  1. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,320
    I don't know why for the life of me I can't seem to make a simple button work for Onclick. I'm doing it exactly how the tutorials shows.
    Latest version of Unity 4.6.1f1

    I create a gameobject called Login Manager
    attached the script below called login_manager to the game object Login Manager.

    Create a canvas
    Create a button as a child of canvas and name it Login Button

    Drag Login Manager into Onclick
    Select the function login in the drop down box.

    I hit play and click the button and debug.Log shows nothing in the console?

    Anyone know what I'm doing wrong here





    Code (csharp):
    1.  
    2.  
    3.  
    4. using UnityEngine;
    5. using System.Collections;
    6. using UnityEngine.UI;
    7. #if UNITY_EDITOR
    8. using UnityEditor;
    9. #endif
    10. public class login_manager : MonoBehaviour {
    11.  
    12.        public void Login(){
    13.  
    14.               Debug.Log ("Logged In");
    15.  
    16.        }
    17. }
    18.  
    19.  


     
    Last edited: Jan 31, 2015
  2. LunaticEdit

    LunaticEdit

    Joined:
    May 1, 2014
    Posts:
    59
    Did you add an EventSystem object? You need one of those too ;)

    Create -> UI -> EventSystem
     
    Kiwasi likes this.
  3. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,320
    Hey LunaticEdit. thanks a lot mate. That was my problem lol. Now I can move forward :)
     
  4. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,320
    I have one other issue regarding input fields. Maybe its the same issue? I have this issue where when I click on a input field there is no carrot and doesn't let me type. So I just now added a event system and now im thinking do I need to activate the input field?

    For some reason there is no tutorials on using input fields.
     
  5. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,320
    The Input Field script can be added to any existing Text control object from the menu (Component > UI > Input Field). Having done this, you should also drag the object to the Input Field’s Textproperty to enable editing.

    The manual says long as a text component is added to a input field it should editable
     
  6. LunaticEdit

    LunaticEdit

    Joined:
    May 1, 2014
    Posts:
    59
    I can tell you from the experience I've had doing my UI library that input fields are ~really~ broken. The best I can say is to look at all of the components of the game object and sub game objects to make sure the 'font' property is set -- typically it's not and you have to spend a large amount of time fiddling with it. Typically no cursor = no font. And keep in mind it generates all kinds of stuff just for the text field. My UI library has about 45 lines of code to set up a functional text editor.