HI guyz, another stupid question, i want my gui text to appear when i press a button, same as the animations. i was wondering if you could use this script and change it to make the gui appear and disappear when i press a certain button any help much appreciated.
function Update ()
{
if(Input.GetButtonDown(“r”))
{
animation.Play(“Reload”);
}
}
maybe -----------------------------------------
function Update ()
{
if(Input.GetButtonDown(“r”))
{
GUItext.Play(“Reload”); or something like this…i have no idea!
}
}
Hi,
I’m away from my dev machine so this is just pseudo code, but it should get you going (it may even compile)…
function Update ()
{
if(Input.GetButtonDown("Reload") )
{
gameObject.guiText.text="Reload";
gameObject.guiText.enabled=true;
}
else if(Input.GetButtonUp("Reload"))
{
gameObject.guiText.enabled=false;
}
}
This code is NOT ideal and will only work with this script dragged onto the GUIText object. You don’t need the ‘gameObject’ if using this script on a single GUIText object, but I left them in so you’d know what to alter if you are accessing Text on a different GameObject. You can also hardcode the “Reload” text into the Inspector, but again, i’ve left it in incase you need to alter it via code.
You will also need your Reload key setup within Unity.
Anyway, have a read up on GUIText and I hope this gets you going in a forward direction.
Regards,
Matt.