using UnityEngine;
using System.Collections;
public class GUI_Menu : MonoBehaviour {
//Variable Start
public GUISkin customSkin;
}
void OnGUI()
{
GUI.skin = customSkin;
}
Then you could just use the unity GUI to add a texture to a button.
I have added this code in GameData script which is attached to GameManager object I want this button in my BeginState script. Now I am adding a button using" if (GUILayout.Button(manager.gameDataRef.customSkin))" in BeginState⦠I am getting compiler errors as
Assets/Code/States/BeginState.cs(32,39): error CS1502: The best overloaded method match for `UnityEngine.GUILayout.Button(UnityEngine.Texture, params UnityEngine.GUILayoutOption[ ])ā has some invalid arguments
Assets/Code/States/BeginState.cs(32,39): error CS1503: Argument #1' cannot convert UnityEngine.GUISkinā expression to type `UnityEngine.Textureā
Please tell me the correct method to achieve thisā¦
Button works perfectly in editorā¦but when I connect with remote in android phoneā¦I found a problem that button works only if my mouse pointer is on the button in editorā¦now whats that:face_with_spiral_eyes:
If you want to have a lot of custom buttons, each of them using a different texture, create some GUITextures, then use on script attached to them : OnMouseDown, OnMouseEnter and OnMouseExit functions. attach the script to the GUITexture, create prefab and instantiate/destroy as needeed.
You canāt call OnMouseDown from another script. On mouse down is called if the mouse button is pressed and that the mouse cursor is on the GUITexture that contain the OnMouseDown function. But you can put some āifā statement inside the OnMouseDown function Or call functions, that can be static if you want them in another script, if you want the said button to work only if something. Or you can instantiate the button only if something (from another script) and destroy it when you donāt want it on screen.
But to be honest, i donāt understand why you would like to call OnMouseDown from another script. And you canāt.
function OnMouseDown(){
if(something){
DoSomething();
}
}
Actually I am working in state machine so I have all splashscreens, buttons in one script which I want to use in another states scripts ā¦I am using splashscreens, GUI.Button using dot syntax but I am not sure about your idea of attaching OnMoseDown to GUITexture using it wherever required:face_with_spiral_eyes: