mirror of
https://github.com/PashaBibko/The-Mobius-Line.git
synced 2026-04-03 17:39:03 +00:00
Final touches
This commit is contained in:
14
Assets/Scripts/KillPlayerOnCollision.cs
Normal file
14
Assets/Scripts/KillPlayerOnCollision.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class KillPlayerOnCollision : MonoBehaviour
|
||||
{
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.CompareTag("Player"))
|
||||
{
|
||||
PlayerMovement.Instance().Kill();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/KillPlayerOnCollision.cs.meta
Normal file
11
Assets/Scripts/KillPlayerOnCollision.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f2fde010c43e15d4893fce8d399cb999
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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
|
||||
(
|
||||
|
||||
@@ -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; }
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user