Final touches

This commit is contained in:
Pasha Bibko
2025-04-28 10:16:14 +01:00
parent 16bcb9b203
commit f4d15f33e7
12 changed files with 1719 additions and 675 deletions

View File

@@ -49,6 +49,12 @@ public class CameraController : MonoBehaviour
// Update is called once per frame
void Update()
{
if (PlayerMovement.Instance().IsDead())
{
transform.position = m_Tracking.position;
return;
}
// Gets the mouse input from the user
Vector2 mouse = new Vector2
(

View File

@@ -4,6 +4,22 @@ public partial class PlayerMovement : MonoBehaviour
{
private void OnTriggerStay(Collider other)
{
if (m_IsDead)
{
return;
}
if (other.CompareTag("Finish"))
{
m_IsDead = true;
m_GameCanvas.enabled = false;
m_CompletedCanvas.enabled = true;
float timeTaken = Time.time - m_StartTime;
m_CompletedText.text = "Congratulations you beat 'The Mobius Line'\nYou took " + timeTaken.ToString("0.00") + " seconds\nPress R to restart and try to get a faster time";
}
// Stops it trying to find the normals of portals
if (other.CompareTag("Portal")) { return; }

View File

@@ -22,6 +22,11 @@ public partial class PlayerMovement : MonoBehaviour
// Fixed Update is called once per physics update
private void FixedUpdate()
{
if (m_IsDead)
{
return;
}
// Resets portal state
m_PortalFrameCounter = Mathf.Max(0, m_PortalFrameCounter - 1);

View File

@@ -41,6 +41,12 @@ public partial class PlayerMovement : MonoBehaviour
[SerializeField] Transform m_Orientation;
[SerializeField] Transform m_PlayerTransform;
[Header("Canvases")]
[SerializeField] Canvas m_GameCanvas;
[SerializeField] Canvas m_DeadCanvas;
[SerializeField] Canvas m_CompletedCanvas;
[SerializeField] Text m_CompletedText;
[Header("Debug Settings")]
[SerializeField] Text m_SpeedDisplay;
@@ -85,6 +91,10 @@ public partial class PlayerMovement : MonoBehaviour
//
int m_PortalFrameCounter = 0;
bool m_IsDead = false;
float m_StartTime;
// Only instance of the player
static PlayerMovement s_Instance;
@@ -98,6 +108,12 @@ public partial class PlayerMovement : MonoBehaviour
// Start is called before the first frame update
private void Start()
{
m_StartTime = Time.time;
//
m_CompletedCanvas.enabled = false;
m_DeadCanvas.enabled = false;
// Checks there is not more than one player at one time
if (s_Instance != null)
{
@@ -121,4 +137,19 @@ public partial class PlayerMovement : MonoBehaviour
// Allocates memory for the list of collisions
m_WallCollisions = new List<Collider>();
}
public void Kill()
{
if (m_IsDead)
{
return;
}
m_IsDead = true;
m_GameCanvas.enabled = false;
m_DeadCanvas.enabled = true;
}
public bool IsDead() { return m_IsDead; }
}

View File

@@ -45,6 +45,17 @@ public partial class PlayerMovement : MonoBehaviour
// Update is called once per frame
private void Update()
{
// Reloads the game to stop falling off
if (Input.GetKey(KeyCode.R))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
if (m_IsDead)
{
return;
}
// Performs raycasts to see what the player is standing on
m_Grounded = Physics.Raycast(transform.position, Vector3.down, out m_StandingOn, m_PlayerHeight * 0.5f + 0.3f, m_GroundMask);
m_OnSlope = m_StandingOn.normal != new Vector3(0.0f, 1.0f, 0.0f) && m_Grounded;
@@ -60,11 +71,5 @@ public partial class PlayerMovement : MonoBehaviour
// Displays the speed of the player to the screen
m_SpeedDisplay.text = new Vector3(m_Body.velocity.x, 0.0f, m_Body.velocity.z).magnitude.ToString("0.00") + " m/s";
// Reloads the game to stop falling off
if (Input.GetKey(KeyCode.R))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
}