Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Unity 5.6: OnClick() not working...

Discussion in 'UGUI & TextMesh Pro' started by SmashedPotatoStudios, Apr 29, 2017.

  1. SmashedPotatoStudios

    SmashedPotatoStudios

    Joined:
    Apr 29, 2017
    Posts:
    3
    Hi.

    I'm having a VERY frustrating issue with a main menu I'm creating... below is a link to the problem in the LinusTechTips forum (Which is great BTW). :

    https://linustechtips.com/main/topi...ot-working-still-help-please-very-frustrated/


    Or you can just read it here:



    I got a problem.



    Im making a menu for a game in unity 5.6. I am using this tutorial:



    https://unity3d.com/learn/tutorials/topics/user-interface-ui/creating-main-menu?playlist=17111



    In this part of the video:



    He adds the script, hits a dropdown menu and then goes LoadSceneOnClick > LoadByIndex(int), and then sets "LoadByIndex" to 1. When I hit the dropdown menu, the only option is "MonoScript", and then "Sting name":



    Even if I input "1" into the box, nothing happens when I play the scene. Here is my script:



    using UnityEngine;
    using System.Collections;
    using UnityEngine.SceneManagement;

    public class LoadSceneOnClick : MonoBehaviour {

    public void LoadByIndex(int sceneIndex)
    {
    SceneManager.LoadScene (sceneIndex);
    }
    }






    Using unity 5.6. HOW TO FIX!?!?!? Getting frustrated.


    All help appreciated!!!
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    The problem is that you have to add the script to a gameobject in the scene (any one will do). Then, you add that same gameobject to the spot where you previously added the script. This is a small bit of knowledge that virtually everyone has to learn when they start. :)
    Then, you will see the drop down menu showing you the right information (whatever's in the video).
     
    JohnnyGo-Time likes this.
  3. SmashedPotatoStudios

    SmashedPotatoStudios

    Joined:
    Apr 29, 2017
    Posts:
    3

    THANK YOU! IT WORKED!!
     
  4. JohnnyGo-Time

    JohnnyGo-Time

    Joined:
    Aug 8, 2021
    Posts:
    17
    WHAT THE HECK. Thank you so much. This is the kind of subtle thing that could cause people (me, at least!) to just bounce off Unity forever. Is there no way they could nudge us to do that a bit more clearly inside the editor??