Made respawn when hit centre
This commit is contained in:
@@ -425,7 +425,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 1b1a209741ad95946a6f0138e93431c4, type: 3}
|
m_Script: {fileID: 11500000, guid: 1b1a209741ad95946a6f0138e93431c4, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
m_RadiusSpeed: 2
|
m_RadiusSpeed: 0.5
|
||||||
m_DistanceSpeed: 0.6
|
m_DistanceSpeed: 0.6
|
||||||
m_GapDistance: 1
|
m_GapDistance: 1
|
||||||
m_RingPrefab: {fileID: 8276642441649562681, guid: 2b69b065f2beade4d91167a23508e29e, type: 3}
|
m_RingPrefab: {fileID: 8276642441649562681, guid: 2b69b065f2beade4d91167a23508e29e, type: 3}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@@ -41,6 +42,8 @@ public class GlobalOrbitalPositionManager : MonoBehaviour
|
|||||||
private OrbitalPosition m_PlayerOrbitalPosition;
|
private OrbitalPosition m_PlayerOrbitalPosition;
|
||||||
public static void SetPlayer(OrbitalPosition player) => s_Instance.m_PlayerOrbitalPosition = player;
|
public static void SetPlayer(OrbitalPosition player) => s_Instance.m_PlayerOrbitalPosition = player;
|
||||||
|
|
||||||
|
public static bool AllowPlayerInput { get; private set; } = true;
|
||||||
|
|
||||||
private float m_TimeOfLastRingSpawn = float.NegativeInfinity;
|
private float m_TimeOfLastRingSpawn = float.NegativeInfinity;
|
||||||
|
|
||||||
private int m_LastGeneratedRing;
|
private int m_LastGeneratedRing;
|
||||||
@@ -67,14 +70,42 @@ public class GlobalOrbitalPositionManager : MonoBehaviour
|
|||||||
z: 0
|
z: 0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RestartSimulation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool s_RestartingSimulation = false;
|
||||||
|
|
||||||
|
private static IEnumerator RestartSimulationInternal()
|
||||||
|
{
|
||||||
|
//if (s_RestartingSimulation)
|
||||||
|
// yield break;
|
||||||
|
|
||||||
|
s_RestartingSimulation = true;
|
||||||
|
|
||||||
|
Time.timeScale = 3.5f;
|
||||||
|
AllowPlayerInput = false;
|
||||||
|
for (int i = 0; i < 500; i++)
|
||||||
|
{
|
||||||
|
yield return new WaitForEndOfFrame();
|
||||||
|
s_Instance.m_PlayerOrbitalPosition.m_AttachedRing = s_Instance.m_LastGeneratedRing;
|
||||||
|
}
|
||||||
|
|
||||||
|
yield return new WaitForSeconds(4f * Time.timeScale);
|
||||||
|
AllowPlayerInput = true;
|
||||||
|
Time.timeScale = 1f;
|
||||||
|
|
||||||
|
s_RestartingSimulation = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RestartSimulation() => s_Instance.StartCoroutine(RestartSimulationInternal());
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
if (Time.time - m_TimeOfLastRingSpawn > GlobalOrbitalSettings.GapDistance)
|
if (Time.time - m_TimeOfLastRingSpawn > GlobalOrbitalSettings.GapDistance)
|
||||||
{
|
{
|
||||||
GameObject newRing = Instantiate(GlobalOrbitalSettings.RingPrefab);
|
GameObject newRing = Instantiate(GlobalOrbitalSettings.RingPrefab);
|
||||||
newRing.transform.localScale = new Vector3(10f, 10f, 1);
|
newRing.transform.localScale = new Vector3(12f, 12f, 1);
|
||||||
|
|
||||||
Ring ring = newRing.AddComponent<Ring>();
|
Ring ring = newRing.AddComponent<Ring>();
|
||||||
ring.m_ID = m_LastGeneratedRing + 1;
|
ring.m_ID = m_LastGeneratedRing + 1;
|
||||||
@@ -126,8 +157,8 @@ public class GlobalOrbitalPositionManager : MonoBehaviour
|
|||||||
{
|
{
|
||||||
if (!m_Distances.ContainsKey(orbitalPosition.m_AttachedRing))
|
if (!m_Distances.ContainsKey(orbitalPosition.m_AttachedRing))
|
||||||
{
|
{
|
||||||
orbitalPosition.m_Behaviour.OnReachCentre();
|
|
||||||
orbitalPosition.m_AttachedRing = m_LastGeneratedRing;
|
orbitalPosition.m_AttachedRing = m_LastGeneratedRing;
|
||||||
|
orbitalPosition.m_Behaviour.OnReachCentre();
|
||||||
}
|
}
|
||||||
|
|
||||||
float distance = m_Distances[orbitalPosition.m_AttachedRing];
|
float distance = m_Distances[orbitalPosition.m_AttachedRing];
|
||||||
@@ -156,7 +187,7 @@ public class GlobalOrbitalPositionManager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Random.Range(0, 20) == 0)
|
if (Random.Range(0, 20) == 0 && AllowPlayerInput)
|
||||||
Instantiate(GlobalOrbitalSettings.EnemyPrefab);
|
Instantiate(GlobalOrbitalSettings.EnemyPrefab);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ public class PlayerController : OrbitalPositionBehaviour
|
|||||||
GlobalOrbitalPositionManager.SetPlayer(m_OrbitalPosition);
|
GlobalOrbitalPositionManager.SetPlayer(m_OrbitalPosition);
|
||||||
|
|
||||||
m_OrbitalPosition.m_ObjectRadius = 0.4f;
|
m_OrbitalPosition.m_ObjectRadius = 0.4f;
|
||||||
m_OrbitalPosition.m_SpinSpeed = 0.05f;
|
m_OrbitalPosition.m_SpinSpeed = 0.1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
if (Input.GetKeyDown(KeyCode.Space))
|
if (Input.GetKeyDown(KeyCode.Space) && GlobalOrbitalPositionManager.AllowPlayerInput)
|
||||||
{
|
{
|
||||||
m_OrbitalPosition.m_AttachedRing += 1;
|
m_OrbitalPosition.m_AttachedRing += 1;
|
||||||
}
|
}
|
||||||
@@ -22,4 +22,9 @@ public class PlayerController : OrbitalPositionBehaviour
|
|||||||
{
|
{
|
||||||
Debug.Log("HIT OBSTACLE IG");
|
Debug.Log("HIT OBSTACLE IG");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void OnReachCentre()
|
||||||
|
{
|
||||||
|
GlobalOrbitalPositionManager.RestartSimulation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user