- Home /
How do I place buttons on the screen using GUITexture?
Hi, I don't want to use guibuttons but guitextures to show buttons on my screen. I looked up guitextures in the manual am still confused about how to place and size them on the screen. I am particularly confused about the scale of the guitexture and the pixel insets. A detailed explanation would be highly appreciated. Thanks...
Answer by PommPoirAbricot · Jun 19, 2014 at 09:26 AM
Try to play between 0 and 1 with the x, y, z of the position of the transform component of your GUITexture gameobject
Because your GUITexture is a GameObject with at least 2 components : Transform and GUITexture
Does it works for you ?
Answer by rsamrry · Jun 19, 2014 at 09:42 AM
Do you want me to play with the position or the scale
Thanks, that worked. Actually my guitexture was a child of another game object, so its coordinates were being influenced by the parent's coordinates. when i moved the guitexture up it solved my problem.
Answer by St4va · Jun 19, 2014 at 11:25 AM
C#
This should help, play with the options in the "Inspector" menu
Code:
using UnityEngine; using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
public GUIStyle Changing_Texture; public float OutlinedTextureY; public float OutlinedTextureX;
void OnGUI(){
if (GUI.Button (new Rect (Screen.width * OutlinedTextureX, Screen.height * OutlinedTextureY, Screen.width * .175f, Screen.height * .025f),"", Changing_Texture))
{print("Changed");}
}
}
Thank you but I don't want to use GUI.Button. I want to use GUI.Texture and want to be able to place these textures anywhere on the screen from my script.