This is a painfully small thing, yet I cant seam t figure it out. I’m trying to figure out how to make a texture a button, here’s what I have so far:
var crosshair : Texture;
function OnGUI () {
GUI.Label(Rect(200,50,150,30), "Main Menu");
if(GUI.Button(Rect(200,100,150,30),crosshair)) {
Application.LoadLevel("dominated");
}
}
and I get error message:
Actor::updateMassFromShapes: Compute mesh inertia tensor failed for one of the actor’s mesh shapes! Please change mesh geometry or supply a tensor manually!
I dragged an image from the project view into the var in the inspector. I’ve searched the forums and been through the scripting references, any input is appreciated.
trying using GUI skin, this will get rid of the unity button background though, but with this you can make your own.
Thanks I’ll check it out.
you have to make a GUI texture
http://unity3d.com/support/documentation/Components/class-GuiTexture.html
then if you want to make it clickable, you have to make a guiHitTest command
private var gui : GUITexture;
function Start(){
gui=GetComponent(GUITexture);
}
function Update(){
if (gui.HitTest(Input.mousePosition))
{
if(Input.GetMouseButtonDown(0))
{
guiTexture.color = Color(.2,.2,.2);
}
if (Input.GetMouseButtonUp(0))
{
guiTexture.color = Color(.5,.5,.5);
}
}
}
also select your texture file in unity, and in the inspector change it from “texture” to GUI, so it keeps the proportions of your gui texture