- Home /
Clicking Trigger
Hello everyone, thanks for your time!
I want the user to click the screen to get a message.(In this case, where the user clicked). Now there are some buttons on the screen but I don't want the message to appear if the user clicked those buttons.
Is there a way to manage around this problem?(so when the user clicks the buttons, there's no message popUp?)
Here's what Im using for the code:
if(Input.GetMouseButtonDown(0))
{
Debug.Log("Clicking");
dist = transform.position.z - _camera.transform.position.z;
userInputPosition = (new Vector3(Input.mousePosition.x, Input.mousePosition.y, dist));
userInputPosition = _camera.ScreenToWorldPoint (userInputPosition);
Message ();
//Send PopUp();
}
Why don't you use the new unity ui or are you using 3d mesh text? Anyway you should post rest of your code. What is in the $$anonymous$$essage()? Is "PopUp" text?
@Avash Im using New because The "world" moves. The idea is that the user clicks the "world" and gives you a debug of where you clicked(in the "world"). As the script is attached to a camera we have to convert from camera to "world" point....
$$anonymous$$essage() does nothing really, just gives a Debug that says "You should add the code of a popUp"
But that debug message gets called even when I clicked a button. I don't want the events to be called if Im clicking GUI. Just the "world" screen.
Thanks for your time.
So in quick words, I want to ignore the script when Im clicking GUI.
@Avash Never$$anonymous$$d I thought you meant the (new vector3... Im just downloading Unity 4.6. So, what exactly do you mean by using the new. Won't it be just the same? or what exactly should I be looking at with the new Unity?
Answer by Avash · Nov 29, 2014 at 09:03 PM
You should probaly use raycast and check is mouse pointing to the right collider (trigger) and mouse button down at the same time.
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
Raycasthit hit;
Physics.Raycast (ray, hit, 5);
if(Input.GetMouseButtonDown(0) && hit.collider.name == "YourGameObjectName"){
Message ();
}
EDIT: http://answers.unity3d.com/questions/777818/46-ui-calling-function-on-button-click-via-script.html
@Avash Is it possible to do something like:
!hit.collider.name == "GUI" ??
The problem I see in this is that If I add more objects(Which I was thinking about..) I must do a check for each object in the name area...
So I guess its easier to exclude GUI, but I don't know if GUI has colliders...
$$anonymous$$ake buttons in the editor, assign them in script and use onClick.