- Home /
Trying to view paper object on button press GUI Texture
Trying to get it so when the player is within distance of a "paper" object, looking at it and hits the F key it will display a GUI texture to the screen then you can hit F (or any other key if needed) again to exit. Also one with the same functionality but a little added to it.
READ PAPER EXAMPLE 1: Character see's paper on a desk, when they are within 5' of this object and are looking at it and hit the F key it pops a GUI texture of the paper on the screen when they hit F again it exits.
READ PAPER/LOAD LEVEL EXAMPLE 2: Character see's paper on a desk, when they are within 5' of this object and are looking at it and hit the F key it pops a GUI texture of the paper on the screen then when they hit F again it exits and loads character to another level.
If they cannot use the same button F for looking at the GUI texture AND exiting that is fine to substitute a different key press.
If you answer since I suck at scripting/programming in general please state specific's and please let me know if it C# or Java.
Thank you ahead of time for any and all help.
Answer by MadToLove · Sep 18, 2012 at 10:19 AM
This was exactly what I was looking for. http://answers.unity3d.com/questions/302087/read-notes-like-amnesiapenumbra.html
Answer by Kirbyrawr · Sep 17, 2012 at 09:47 PM
Okey NO one is born knowing, but I suggest you to look a tutorial:
I can share with you my script
#pragma strict
var YOUROBJECTTransform : Transform;
private var Gui = false;
function OnMouse()
{
if(Vector3.Distance(YOUROBJECTTransform.position, transform.position) > 4) return;
Gui = true;
}
function OnGUI(){
if(Gui == true){
if(GUI.Button(Rect(650,150,100,50), "OPEN THE PAPER")){
//DO YOUR ACTION HERE
}
if(Vector3.Distance(YOUROBJECTTransform.position, transform.position) < 4) return;
Gui = false;
}
}
You need to attach this script to your character , when the character is near the object (paper or anything) and the mouse is over the object , gui pop out with a button , if you touch this button you can perform an action like guitext from the paper or anything you want
Hope it helps ^^
//IS JAVASCRIPT OR JS!
The note object, but actually this script is really old xD
Answer by sig · Sep 18, 2012 at 06:01 AM
Clues:
http://docs.unity3d.com/Documentation/ScriptReference/Input.GetKeyDown.html - use that example to detect if KeyCode.F was pressed
http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html - use those examples to detect what object mouse is pointing at (see the last example snippet)
Remember to add relevant tags to detect "paper" - http://docs.unity3d.com/Documentation/Components/class-TagManager.html
use C#
Good luck!