62 lines
1.6 KiB
C#
62 lines
1.6 KiB
C#
using UnityEngine;
|
|
|
|
public class PlayerController : OrbitalPositionBehaviour
|
|
{
|
|
private static PlayerController s_Instance;
|
|
public static bool IsPlayerAttached => s_Instance.m_OrbitalPosition.m_IsAttachedToRings;
|
|
public static void AttachPlayer() { s_Instance.m_OrbitalPosition.m_IsAttachedToRings = true; }
|
|
|
|
private Vector3 m_SuicidePoint;
|
|
private bool m_KillingItself = false;
|
|
private float m_DeathLerp = 0f;
|
|
|
|
public MeshRenderer m_Renderer;
|
|
|
|
protected override void OnStart()
|
|
{
|
|
s_Instance = this;
|
|
|
|
GlobalOrbitalPositionManager.SetPlayer(m_OrbitalPosition);
|
|
|
|
m_OrbitalPosition.m_ObjectRadius = 0.4f;
|
|
m_OrbitalPosition.m_SpinSpeed = 0.2f;
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.Space) && GlobalOrbitalPositionManager.AllowPlayerInput)
|
|
{
|
|
m_OrbitalPosition.m_AttachedRing += 1;
|
|
}
|
|
|
|
if (!m_KillingItself)
|
|
return;
|
|
|
|
transform.position = Vector3.Lerp(m_SuicidePoint, Vector3.zero, m_DeathLerp);
|
|
m_DeathLerp += Time.deltaTime;
|
|
|
|
}
|
|
|
|
public override void OnCollision(OrbitalPositionBehaviour other)
|
|
{
|
|
if (!m_OrbitalPosition.m_IsAttachedToRings)
|
|
return;
|
|
|
|
GlobalOrbitalPositionManager.RestartSimulation();
|
|
m_SuicidePoint = transform.position;
|
|
m_KillingItself = true;
|
|
m_DeathLerp = 0f;
|
|
}
|
|
|
|
public override void OnSimulationRestart()
|
|
{
|
|
m_KillingItself = false;
|
|
m_Renderer.enabled = true;
|
|
}
|
|
|
|
public override void OnReachCentre()
|
|
{
|
|
GlobalOrbitalPositionManager.RestartSimulation();
|
|
}
|
|
}
|