Hello YE i have wrote a code and it doesn’t work basicly what im trying to do it make it so that what i hit the aim button it enables a GUITexture and when i let go of it, it disables If you could help that would be great this is the code
var Aim : boolean = false;
var Snip texture : GUITexture
function Update ()
{
if(Input.GetMouseButtonDown(1))
{
Aim = true;
if(Aim == true)
{
Snip texture.active = true;
}
}
if(Input.GetMouseButtonUp(1))
{
Aim = true;
if(Aim)
{
Snip texture.active = false;
}
}
}
You have a bunch of issues…
Try this…
var Aim : boolean = false;
var SnipeTexture : GUITexture;
function Update ()
{
if(Input.GetMouseButton(1))
{
Aim = true;
}
if(Input.GetMouseButtonUp(1))
{
Aim = false;
}
if(SnipeTexture == null)
return;
if(Aim)
{
SnipeTexture.enabled = true;
}
if(!Aim)
{
SnipeTexture.enabled = false;
}
}
This code doesn’t make much sense. Aim is set to true in both cases, and Snip texture isn’t a valid variable name (you can’t have spaces inside the name). You could do it in a simpler way with something like this:
var Aim : boolean = false;
var SnipTexture : GUITexture;
function Update ()
{
Aim = Input.GetMouseButton(1);
SnipTexture.active = Aim;
}
NOTE: Unity will complain that active is obsolete, and that you should use gameObject.active instead.