How to move a GameObject to the mouse position?

I have this so far:

pragma strict

var cardmove : GameObject;

function Start () { cardmove.gameObject.transform = KeyCode.Mouse0; }

function Update () {


I am trying to move the cardmove Gameobject that i assign, but when I try to add the Keycode.Mouse0 to my code I get a read only error? How can I fix the read only error and get my script to work? Can someone help me with this thanks!

more ▼

asked Aug 09, 2013 at 08:19 PM

thecookie12 gravatar image

7 9 13 15

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

2 answers: sort voted first

you cant set a enumeration value (KeyCode.Mouse0) effectively an int to a Transform(a much more complex struct then anyone gives it credit)

if you want the Vector2 mousePosition Reletive the screen you would use Input.mousePosition though you will need to do work of this to get anything of real value in 3d space.

if you want to know like where the mouse interacts with respect to an object then you would use screen point to ray with respect to the mousePosition

more ▼

answered Aug 09, 2013 at 08:45 PM

gardian06 gravatar image

891 52 64 76

(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



Answers and Comments



asked: Aug 09, 2013 at 08:19 PM

Seen: 656 times

Last Updated: Aug 09, 2013 at 08:46 PM