- Home /
Button's Click through problem? Help?
Hello! I am a novice in Unity and scripting. Of course I am having problems with lot of stuff. In my scene, I put some buildings and three cameras. On first camera I apply script for rotate on mouse drag and rotate on mouse scroll. Second camera auto rotates around the scene and third is First person camera. I use script for switching between cameras on three buttons. That all work very good but when i click on button and drag on it, camera in my scene is draging(rotating) to. I realize that i have click through problem. I am looking for a solution, reading other questions and answers but no luck for now.
Can someone help me on this please?
Answer by rob5300 · Dec 18, 2014 at 03:20 PM
If you are using the new 4.6 ui system, then make sure there is an EventSystem in the hierarchy. This is required to perform the internal ray casting to make UI objects intractable. If this is not the case, add a screenshot showing is the editor view with the button in question selected.
Edit: An EventSystem can be made by going to Create > UI > EventSystem.
Thanks for reply. I am using new UI sytem, and i have EventSystem in my scene. Can you give some information how can i make my UI objects intractable.
$$anonymous$$y scene contain: -Building, -cameras (autorotating, on drag/rotate scroll/zoom, and FPS Controller(buit in Unity) with camera) --Canvas>Plane>Three buttons that contain script's (for selecting active camera) and On Click () function in inspector view I select that button's as a game object's and attach function from script On$$anonymous$$ouseDown (). EventSystem
Thanks again, I am a begginer in Unity/Scripting, but I like to learn to do "simple" things like this.
From what you have said here, this should work fine. (You said Plane, do you mean an image?) When you click the button, does the button still activate as well as the camera movement, or is just the camera movement working? Please take a screenshot of your hierachy with the canvas children in view the button selected in the inspector.
I am sorry, i wrote "Plane", What I really wanted to write is "Panel". Button is working perfectly and camera movement is working when drag on button.! alt text
That's okay. I believe the reason this is happening is quite simple. I assume the method you use to rotate the camera is by using an if statement for Input.Get$$anonymous$$ouseButtonDown for left click. The code will still activate the code as the left click has happened, it doesn't care if it hits a button or not. If this is the case, you need to have the script that rotates the camera eathier disabled until required or also check if the correct mode is active. This should then restrict the camera panning to only when required.
Edit: I hope this is clear enough. Just remember that code looking for a left click will activate when a left click occurs. That is the problem in coding, you often have to be very specific in your code to prevent accidental firing.
Your answer
Follow this Question
Related Questions
Click and Drag not Clicking or Dragging 2 Answers
Access NGUI button's notify(OnClick) 1 Answer
Can I change GUIButton behaviour? 1 Answer
Convert vector in world to mesh 1 Answer