Files
grass-cutters/Assets/Scripts/Core/MenuCamera.cs
NiemandKG d1c3761e58 Grass Cutters Together: the project as of moon-sweepers f3666f0
A clean start for the shared repository: the Unity project (Assets, Packages, ProjectSettings), ArtSource, Docs and
Tools as they stood at f3666f0 in the old local repository, with its generated prefabs and scene brought up to date.
Images, audio, models and binaries go through Git LFS (.gitattributes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 18:44:40 +06:00

46 lines
1.4 KiB
C#

using UnityEngine;
namespace GrassCutter
{
/// <summary>Slow cinematic drift around the ocean rig while in the main menu. Gives the camera to the local player in game.</summary>
public class MenuCamera : MonoBehaviour
{
static MenuCamera _i;
public Transform cam;
public Vector3 focus = new Vector3(0f, 2.5f, 0f);
public float radius = 22f, height = 7f, speed = 0.02f;
bool _active = true;
float _t;
void Awake()
{
_i = this;
if (!cam && Camera.main) cam = Camera.main.transform;
}
public static void Release()
{
if (_i) _i._active = false;
}
public static void Reclaim()
{
if (!_i || !_i.cam) return;
_i._active = true;
_i.cam.SetParent(_i.transform, false);
CameraFx.FovTarget(0f);
}
void LateUpdate()
{
if (!_active || !cam) return;
_t += Time.unscaledDeltaTime * speed;
float a = _t * Mathf.PI * 2f;
var pos = focus + new Vector3(Mathf.Cos(a) * radius, height + Mathf.Sin(a * 2f) * 0.6f, Mathf.Sin(a) * radius * 0.75f);
cam.position = pos;
cam.rotation = Quaternion.LookRotation(focus + new Vector3(Mathf.Sin(a * 0.7f) * 1.5f, 0, 0) - pos, Vector3.up);
}
}
}