Hi guys
I lost my old account, so I had to create a new
How can I assign the same key? Whatever text appeared and disappeared one key
(Press once, the text appeared, pressed a second time, the text disappeared)
Here’s the code
var nearObject : boolean = false;
var appearText : boolean = false;
var message : String;
public var guiSkin : GUISkin;
function OnTriggerEnter(other : Collider)
{
if(other.gameObject.tag == "Player")
{
nearObject = true;
}
}
function OnTriggerExit(other : Collider)
{
if(other.gameObject.tag == "Player")
{
nearObject = false;
}
}
function OnGUI(){
if(Input.GetKeyUp (KeyCode.E) && nearObject) {
appearText = true;
}
if(appearText){
//show text
Time.timeScale = 0;
GUI.skin = guiSkin;
GUI.Label(Rect(Screen.width/2 - 250, Screen.height- 100,700,150), message);
}
//hide text
if(Input.GetKeyDown (KeyCode.E) && nearObject){
Time.timeScale = 1;
appearText = false;
}
}
And it is possible more in detail?
I’m just new to scripting
as it is tried with this code
but that that did not leave me:hushed:
private var isPressed = false;
function Update {
if (Input.GetKeyDown(KeyCode.E)) {
if (!isPressed) {
//put show text here
isPressed = true;
}
else {
//hide text
isPressed = false;
}
}
}
I am not sure if a GUI element can appear with Time.timeScale being 0. I mean, if it animates in, it needs a timescale, right? Things like NGUI or HOTween have their own timescale, so maybe work with those?
What behavior are you trying to achieve anyway? I bet three if conditions are one too many.
I’ve got one button to respond to the appearance of the text, and the text fading
In this case “E”
Example:
I went to the subject, I press the button “E” text appears, once again shake down the “E” disappears tex
on another note, are you particularly attached to using the OnGUI approach? It was replaced by the new UI system when version 4.6/5 was released. Might be worth learning the new way given that OnGUI is now really only useful for custom editor scripting…