x


OnMouseOver get cursor position on object

I have a camera that's tilted downwards a little and looking at a terrain. I want to make a OnMouseOver script for the terrain. When the mouse moves over the terrain, it gets the position of the mouse over the terrain. Then it moves a waypoint to the mouse position on the terrain. This is not on mouse click, I want the waypoint to continuously follow the mouse as long as it's over the terrain.

how would I do this?

more ▼

asked Oct 24 '11 at 08:05 PM

Jibidiah gravatar image

Jibidiah
16 5 5 7

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

See http://unity3d.com/support/documentation/ScriptReference/Collider.Raycast.html

for example code. You would detect the hit point with raycast, and detect that the mouse is clicked, then instantiate (or move) a waypoint object to that position.

more ▼

answered Oct 24 '11 at 08:33 PM

DaveA gravatar image

DaveA
26.5k 151 171 256

not mouse click, mouse over. so raycast would be invalid

Oct 24 '11 at 09:06 PM Jibidiah

Raycasting doesn't need clicking. It doesn't even need the mouse at all!

Oct 24 '11 at 11:01 PM syclamoth

actually raycasting was exactly what I was looking for, I shall accept this answer.

Oct 24 '11 at 11:55 PM Jibidiah
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x49

asked: Oct 24 '11 at 08:05 PM

Seen: 1361 times

Last Updated: Oct 24 '11 at 11:55 PM