- Home /
Code Error!!!!
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;
}
}
}
Answer by Rod-Green · Nov 02, 2011 at 09:24 PM
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;
}
}
Yeh sorry im not much off a coder :/ also this code gets an error saying somthing about it been obsolete ?? any ideas
I just tested this in the latest 3.4 in an empty project. No error, warnings or any mention of 'obsolete'. You must have some other code somewhere that's using an old method.
ye it was something to do with my project it worked perfectly when i created a new one :) thanks for you help. :D
Answer by aldonaletto · Nov 02, 2011 at 09:18 PM
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.
active will actually disable the GameObject altogether so this needs to be changed to enable to disable / enable the GUITexture..
Ha, thank you Aldonaletto you even $$anonymous$$ched me something. I did not know you could set a variable on Input.GetButtonDown("Blah") gotta use that more. :)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Activating Audio When Hitting a collider 2 Answers
Animation stoping!! 1 Answer
Why doesn't my script work? 1 Answer
Rest postion after animation plays 0 Answers