I’m makin a game in Unity 2D, and need an object to follow the mouse movement in order to make a custom and changeable cursor. This is the code I have currently. At the moment, it follows the mouse, but is displaced from the mouse about of of the screen to the top left, i.e. if the mouse is at the bottom left of the screen, the cursor is in the middle.
Current Code:
using UnityEngine;
using System.Collections;
public class Cursor : MonoBehaviour {
// Use this for initialization
void Start () {
Screen.showCursor = false;
}
// Update is called once per frame
void Update () {
Vector3 mouse = Input.mousePosition;
mouse = mouse * 10F;
transform.position = Camera.main.ScreenToViewportPoint(mouse);
}
}