Hi, so I am trying to make a GUI crosshair which I will later change(based on the weapon’s accuracy). Problem is, I don’t really understand how the GUI system works, since I have only done one thing with it, and I need help. I have an empty game object, with this script
function OnGUI()
{
GUI.Box(Rect(0,0,15,15), "");
}
What else do I need to do to make it appear? Thanks!
#pragma strict
var chTexture : Texture2D;
var positionch : Rect;
static var ch = true;
function Update() // If we don't do this, we can't update the size.
{
positionch = Rect((Screen.width - chTexture.width) / 2, (Screen.height -
chTexture.height) /2, chTexture.width, chTexture.height);
}
//We need to draw the texture on the gui
function OnGUI()
{
if(ch == true)
{
GUI.DrawTexture(positionch, chTexture);
}
}
Attach it to a gameobject, and put a texture in the inspector.
var crosshairTexture : Texture2D;
var position : Rect;
static var OriginalOn = true;
function Start()
{
position = Rect((Screen.width - crosshairTexture.width) / 2, (Screen.height -
crosshairTexture.height) /2, crosshairTexture.width, crosshairTexture.height);
}
function OnGUI()
{
if(OriginalOn == true)
{
GUI.DrawTexture(position, crosshairTexture);
}
}
this script works wonderfully