FANDOM


A "GameCamera 2D" camera type follows the player character by default, but it can be made to follow the cursor instead with a simple script.

  1. Create a C# script named FollowCursor.cs, and paste the contents of the script below into it
  2. Create a new GameObject in your scene named "CursorReference"
  3. Attach the new FollowCursor component to the CursorReference GameObject
  4. In your GameCamera 2D, uncheck Target is Player? and assign CursorReference in the new Target field


FollowCursor.cs:

using UnityEngine;
using System.Collections;
using AC;

public class FollowCursor : MonoBehaviour
{

    private void Update ()
    {
        Vector3 mouseWorldPosition = Camera.main.ScreenToWorldPoint (Input.mousePosition);
        mouseWorldPosition.z = 0f;
        transform.position = mouseWorldPosition;
    }

}