Minimizing Camera.main references

This commit is contained in:
Jenny Crowe
2022-02-03 01:25:27 -07:00
parent 39a3444fd5
commit 1b2aca94cd
6 changed files with 32 additions and 18 deletions

View File

@ -7,10 +7,17 @@ namespace RhythmHeavenMania.Common
public class FollowMouse : MonoBehaviour
{
public Vector2 offset;
public Camera cam;
private void Awake()
{
if (cam == null)
cam = Camera.main;
}
private void Update()
{
var pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
var pos = cam.ScreenToWorldPoint(Input.mousePosition);
transform.position = new Vector3(pos.x - offset.x, pos.y - offset.y, 0);
}
}