- Home /
Question by
jimmyismike · Nov 09, 2011 at 10:44 PM ·
guizoomcrosshair
Crosshair Help
This is my crosshair script,
var crosshairTexture : Texture2D;
var position : Rect;
function Start()
{
position = Rect( ( Screen.width - crosshairTexture.width ) / 2, ( Screen.height - crosshairTexture.height ) / 2, crosshairTexture.width, crosshairTexture.height );
}
function OnGUI()
{
GUI.DrawTexture(position, crosshairTexture);
}
How Can I set it so you can only see the crosshair when you hold mouse 1, then when you let go of mouse 1 the crosshair disappears.
Comment
Best Answer
Answer by ocularcash · Nov 10, 2011 at 06:11 AM
You should be able to deactivate the texture on function Start(), activate it if you press mouse1 and deactivate it on release. I don't know exactly what the function is called, I use keys not mouse, so you'll wanna look it up but it will look like this:
function Start()
{
crosshairTexture.SetActiveRecursively(false);
}
function OnMouseDown()
{
crosshairTexture.SetActiveRecursively(true);
}
function OnMouseUp()
{
crosshairTexture.SetActiveRecursively(false);
}
Your answer
Follow this Question
Related Questions
GUI texture ? help please 0 Answers
GUItexture change on mouseenter 3 Answers
Unity2D - Camera in exported game is zoomed out compared to unity game preview HELP PLEASE! 2 Answers
Sniper zoom with texture 2 Answers
Get variable from another object 1 Answer