Skip to content

Instantly share code, notes, and snippets.

@snarlynarwhal
Created September 12, 2020 14:20
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save snarlynarwhal/9b5b8b56fbd7182e96205974602c37d7 to your computer and use it in GitHub Desktop.
FollowMouse.cs
using UnityEngine;
public class FollowMouse : MonoBehaviour
{
public float positionZ = 0;
private void Update()
{
Vector3 mouseWorldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
mouseWorldPosition.z = positionZ;
transform.position = mouseWorldPosition;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment