Hello everybody,
I have been struggling with that issue, did researches and tried many ways but I have troubles to set an action on the .onclick. I have no issue with the onclick trigger when it is a button defined inside the code, but here, I am working with “wysiwyg button” (click right, add GUI, button)… Among the things I tried, those three:
Here I try to manually give my script to launch on click, but it won’t launch it. I also don’t understand why I don’t have the same menu as all of the youtube tutorial, they usually have a full list of elements from where they can choose events, functions etc… But I just have “No function” and “Monoscript > string name”.
My script is here :
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Nb_gobTVR : MonoBehaviour {
void test1()
{
Debug.Log ("youhouuuu");
}
}
- I’ve tried to call my button inside my script without attaching it, like this :
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Nb_gobTVR : MonoBehaviour {
public button my_butt;
void getmybutton()
{
my_butt = GetComponent<Button>();
}
void Update()
{
if (my_butt)
{
Debug.Log ("youhouuuu");
}
}
}
so I have two questions :
-
How could I manage to get a reaction when the user click on it in both manners (with attaching the script to my button, and with reaching the “wysiwyg” button inside a script).
-
In a global way, for screen scale on different devices or for any other reasons, is it better to create buttons in the code or is it ok to use (what I call) wysiwyg button ?
Thank you for reading,