Unity – Object follow cursor pointer
DRAG AND DROP this script over an Object inside Hierarchy
#pragma strict function Start () { Screen.showCursor = false; } // ------------------------------- // FOLLOW MOUSE POSITION START // ------------------------------- public var depth = 10.0; function FollowMousePosition() { var mousePos = Input.mousePosition; var wantedPos = Camera.main.ScreenToWorldPoint (Vector3 (mousePos.x, mousePos.y, depth)); transform.position = wantedPos; } // ------------------------------- // FOLLOW MOUSE POSITION END // ------------------------------- function Update () { FollowMousePosition(); }
NOTICE: mousePos.x – mousePos.y