Question by
Hewhoisseth · Aug 05, 2017 at 10:14 PM ·
uiraycastraycastinginteraction
How do I add UI pop up with this script?
hello everyone, I want to make it so that when you mouse over a object specified by this script, that you can interact with using raycasting, a UI pops up. So that the player knows they can interact with the object.
Here is my current script so far. #pragma strict
private var guiShow : boolean = false;
var isOpen : boolean = false;
var cleanup : GameObject;
var rayLength = 10;
function Update()
{
var hit : RaycastHit;
var fwd = transform.TransformDirection(Vector3.forward);
if(Physics.Raycast(transform.position, fwd, hit, rayLength))
{
if(hit.collider.gameObject.tag == "cleanup")
{
guiShow = true;
if(Input.GetMouseButtonDown(0) && isOpen == false)
{
cleanup.GetComponent.<Animation>().Play("cleanuppaper");
isOpen = true;
guiShow = false;
}
else if(Input.GetMouseButtonDown(0) && isOpen == true)
{
cleanup.GetComponent.<Animation>().Play("cleanuppaper");
isOpen = false;
guiShow = false;
}
}
}
else
{
guiShow = false;
}
}
Comment
Your answer
Follow this Question
Related Questions
Trouble Raycasting elements in UI in Oculus 0 Answers
Switching from object to object with Raycast Problem 1 Answer
Touchscreens like in the game Prey 0 Answers
Cursor not staying centered to gameobject 0 Answers
Switching between mouse/keyboard and controller for UI navigation (using Input System) 0 Answers