Here’s my script, for some reason it says there’s an expected symbol & parsing error.
But if I take away the GUI Button line on line twelve it works fine.
I just want a GUI Texture to show up when I click on a mesh
Here’s my script:
using UnityEngine;
using System.Collections;
public class OnClick : MonoBehaviour {
public Texture2D texture = null;
public float x = 0;
public float y = 0;
public float x2 = 0;
public float y2 = 0;
void OnMouseDown (){
if (Input.GetKey ("mouse 0")) {
GUI.Button(new Rect(x,y, x2,y2), texture)
}
}
}
public class OnClick : MonoBehaviour {
public Texture2D texture = null;
public float x = 0;
public float y = 0;
public float x2 = 0;
public float y2 = 0;
void OnGUI() {
if ( ! texture ) {
Debug.LogError("Please assign a texture on the inspector");
return;
}
if ( GUI.Button(new Rect(x,y, x2,y2), texture) )
Debug.Log( "Do Something" );
}
}
GUI items only can appear inside the OnGUI function (or some function called by OnGUI). You could in this case set a variable that enables the GUI item - which should be a GUI.Label or GUI.DrawTexture instead of GUI.Button (a button responds to the mouse click, what may cause weird collateral effects). For instance:
...
private bool enableTexture;
void OnMouseDown (){
enableTexture = true; // enable GUI when mouse pressed over object
}
void OnMouseUp (){
enableTexture = false; // disable GUI when mouse button released
}
void OnGUI (){
if (enableTexture){
GUI.Label(new Rect(x,y, x2,y2), texture);
}
}
And remember to end the instructions with a semicolon, like @AyAMrau pointed out.