- Home /
How to handle mouse clicks on terrain?
Hi!
I'm implementing custom editor script that will be used to massively place some objects on terrain, so I need to: 1) handle mouse clicks on terrain, 2) find position on which user have clicked on terrain.
I wonder how to do 1st task?
Answer by Cyb3rManiak · Oct 18, 2010 at 11:43 AM
Use raycasting. A terrain has a collider on it by default, so you can raycast against it without any problem, and receive the position the ray hit it.
Try using the example in the manual: Collider.Raycast
Obviously you can use Physics.Raycast or whatever variant you want...
Ok, but how do I know that user clicked a mouse buton on my Update() method?
Either use the Input class: http://unity3d.com/support/documentation/ScriptReference/Input.html, or ins$$anonymous$$d of putting your code in Update, put it in methods like On$$anonymous$$ouseDown, On$$anonymous$$ouseUp. http://unity3d.com/support/documentation/ScriptReference/$$anonymous$$onoBehaviour.On$$anonymous$$ouseDown.html