ProjectZ/Assets/Scripts/Menu/Person/FollowTheCursor.cs
2024-03-19 21:51:11 +03:00

41 lines
1.1 KiB
C#

using UnityEditor;
using UnityEngine;
using UnityEngine.Animations.Rigging;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
namespace Menu.Person
{
public class FollowTheCursor : MonoBehaviour
{
public Rig targetLayer;
public AudioSource audioSource;
public Transform aimTarget;
public float aimOffset = 1.5f;
public Volume volume;
private Camera _camera;
private DepthOfField depthOfFieldLayer;
private float _a;
void Start()
{
_camera = Camera.main;
targetLayer.weight = 1f;
volume.profile.TryGet(out depthOfFieldLayer);
}
void Update()
{
_a+=0.02f;
depthOfFieldLayer.focalLength.value = Mathf.Sin(_a) * 59f;
Vector2 screenPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
Vector3 worldPosition = _camera.ScreenToWorldPoint(new Vector3(screenPosition.x, screenPosition.y, aimOffset));
aimTarget.position = new Vector3(worldPosition.x, worldPosition.y, aimTarget.position.z);
}
}
}