I have tried Input.MousePosition in multiple ways without success. How do I do it?
(btw, the game is 2d)
I have tried Input.MousePosition in multiple ways without success. How do I do it?
(btw, the game is 2d)
You can probably use Camera.ScreenToWorldPoint().
I can’t get it to work…
Have a look at that (it works).
public var player : Transform;
private var distancePlayerCamera : float;
private var mousePos : Vector3;
private var targetPosition : Vector3;
function Awake ()
{
distancePlayerCamera = transform.InverseTransformPoint (player.position).z;
}
function Update ()
{
mousePos = Input.mousePosition;
targetPosition = camera.ScreenToWorldPoint (Vector3 (mousePos.x, mousePos.y, distancePlayerCamera));
player.position = targetPosition;
}
What is your problem exactly ?
Note : for your information, this script needs an object. The script place the object at the position of the mouse.
Sweet! Thats exactly what I needed.
To be honest, I wrote that yesterday for my own purposes…
Nice timing, huh ?