HeavenStudioPlus/Assets/Scripts/Common/FollowMouse.cs

24 lines
545 B
C#
Raw Normal View History

2022-01-09 23:35:55 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2022-03-14 14:21:05 +00:00
namespace HeavenStudio.Common
2022-01-09 23:35:55 +00:00
{
public class FollowMouse : MonoBehaviour
{
2022-01-11 00:17:29 +00:00
public Vector2 offset;
2022-02-03 08:25:27 +00:00
public Camera cam;
private void Awake()
{
if (cam == null)
cam = Camera.main;
}
2022-01-11 00:17:29 +00:00
2022-01-09 23:35:55 +00:00
private void Update()
{
2022-02-03 08:25:27 +00:00
var pos = cam.ScreenToWorldPoint(Input.mousePosition);
2022-01-11 00:17:29 +00:00
transform.position = new Vector3(pos.x - offset.x, pos.y - offset.y, 0);
2022-01-09 23:35:55 +00:00
}
}
}