- Home /
only show GUI.Button when touched at object on augmented reality
based on the title above...
in my scene there is an object with other functions (Raycasting works on this)..
what i want to do is...
when i touched exactly at the object, GUI BUTTONS appear...
and when i touch anywhere outside of the object... it hides the GUI BUTTONS...
ive tried Raycasting on the object, where i it has the same effect on the other functions..
but if failed...
so is there any other way where i only touch the object for a moment.. and some buttons appear out of nowhere..
and when i touch besides the object the buttons mysteriously disappears..??
heres the code where it works on the keyboard..
function OnGUI () {
if(GUI.Button (Rect (Screen.width/2 - 10, Screen.height/2 - 10, 100, 100), "Hello World!")){
}
}
//this code is in an empty gameobject (myGui)
var Guiscript : myGui;
function Start(){
Guiscript.enabled = false;
}
function Update () {
if(Input.GetKeyDown ("space")){
if (Guiscript.enabled == true){
Guiscript.enabled = false;
}
else {
Guiscript.enabled = true;
}
}
}
so this code works on the keyboard... im having problems to change it to a touch.. as what i explained before..
thank you.. your patience and your help is and honor...
Well raycasting from the camera is the way to go - what didn't work?
the GUI.Buttons..
if i touch the object and only the object... the Buttons will appear... else if i touch else where besides the object.. the Buttons will disappear..
and its an Augmented Reality project...
Answer by svenskefan · Sep 11, 2012 at 12:30 PM
Hi! Seems like you have the logic worked out, only need to get the raycast to work properly.
Make sure you have a collider on the object you want to raycast against, and check out the docs for all possible settings you can have for the raycast call.
i did that...
and it has no effect at all... to make the Buttons appear that is..
Your answer
Follow this Question
Related Questions
Do UI Buttons work the same for Touch for an Android Game? 1 Answer
Help with touchscreen controls 2 Answers
Rotate model with ARKit 0 Answers
Problem with rect and touch 1 Answer