- Home /
Equipment Screen Display
I'm coding an Equipment screen GUI and so far i'm having problems with square one. my script should display a button on the screen when the "e" key is pressed however it is not doing this.
using UnityEngine;
using System.Collections;
public class Equipment : MonoBehaviour
{
public string Kill = "";
void OnGUI()
{
Display();
}
void Display()
{
if(Input.GetKeyDown("e"))
{
GUI.Button(new Rect(200, 200, 200, 200), Kill);
}
}
}
Answer by LastTemplar · Sep 07, 2012 at 05:21 PM
Try using if(Input.GetKey("e")) instead of if(Input.GetKeyDown("e")).
in case you don't want to hold it down, you'll have to add some time interval between the button presses. Do like this (example and explanation here http://docs.unity3d.com/Documentation/ScriptReference/Input.GetButton.html ):
add three variables to your code:
public float fireRate = 0.5F;
private float nextFire = 0.0F;
public bool show;
then, in the update or OnGUI method add this:
if (Input.Get$$anonymous$$ey("e") && Time.time > nextFire) {
nextFire = Time.time + fireRate;
show = !show;
if (!show)
{
GUI.Button(new Rect(200, 200, 200, 200), $$anonymous$$ill);
}
else
{
GUI.Button(new Rect(200, 200, 200, 200), $$anonymous$$ill);
}
Your answer
Follow this Question
Related Questions
Issue with displaying GUI elements 2 Answers
C# script works wrong ( GUI ) How to fix it ? 1 Answer
Dirt On Camera (BF3 and Metro Last Light) 1 Answer
drawing a line through a GUI label 2 Answers
How do I toggle the active state of a canvas UI object 0 Answers