Files
beyond/Assets/Scripts/Utils/ParticlesPlayerFollower.cs

45 lines
1.5 KiB
C#

using UnityEngine;
namespace Beyond
{
public class ParticlesPlayerFollower : MonoBehaviour
{
[Header("Position Settings")]
[Tooltip("How high above the player the rain cloud sits.")]
public float heightOffset = 15f;
[Tooltip("Smooths the movement so rain doesn't snap instantly.")]
public bool useSmoothing = false;
public float smoothSpeed = 10f;
private void Start()
{
// Auto-find Invector player if not assigned
if (Player.Instance == null)
{
Debug.LogWarning("ParticlesPlayerFollower: No Player found! Make sure Player.Instance is set.");
enabled = false;
return;
}
}
void LateUpdate()
{
if (Player.Instance == null) return;
var target = Player.Instance.transform;
// Calculate where the rain emitter should be
// We take the player's X and Z, but override the Y with our offset
Vector3 targetPosition = new Vector3(target.position.x, target.position.y + heightOffset, target.position.z);
if (useSmoothing)
{
transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime * smoothSpeed);
}
else
{
transform.position = targetPosition;
}
}
}
}