Game over.

This commit is contained in:
nexovec 2022-01-29 22:14:15 +01:00
parent a141a6b50a
commit 56b54c73ad
2 changed files with 24 additions and 4 deletions

View File

@ -382,6 +382,14 @@ PrefabInstance:
m_Modification: m_Modification:
m_TransformParent: {fileID: 0} m_TransformParent: {fileID: 0}
m_Modifications: m_Modifications:
- target: {fileID: 3244356566819001086, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3}
propertyPath: distanceFromYAxis
value: 30
objectReference: {fileID: 0}
- target: {fileID: 3244356566819001086, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3}
propertyPath: maxDistanceFromCenterLine
value: 30
objectReference: {fileID: 0}
- target: {fileID: 3244356567786994344, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} - target: {fileID: 3244356567786994344, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3}
propertyPath: m_Name propertyPath: m_Name
value: Player value: Player

View File

@ -4,6 +4,7 @@ using UnityEngine;
public class PlayerController : MonoBehaviour public class PlayerController : MonoBehaviour
{ {
public float maxDistanceFromCenterLine;
[Header("Move")] [Header("Move")]
public float speed = 7.5f; public float speed = 7.5f;
public float maxSpeed = 15.0f; public float maxSpeed = 15.0f;
@ -113,9 +114,9 @@ public class PlayerController : MonoBehaviour
jump = false; jump = false;
} }
if(rb.velocity.magnitude != 0 && Vector3.Dot(rb.velocity.normalized, Physics.gravity.normalized) > 0 ) if (rb.velocity.magnitude != 0 && Vector3.Dot(rb.velocity.normalized, Physics.gravity.normalized) > 0)
{ {
Debug.Log("Player is falling :)"); // Debug.Log("Player is falling :)");
this.isFalling = true; this.isFalling = true;
} }
else else
@ -136,7 +137,8 @@ public class PlayerController : MonoBehaviour
if (pullObject != null) if (pullObject != null)
{ {
PlatformManager platform = pullObject.GetComponent<PlatformManager>(); PlatformManager platform = pullObject.GetComponent<PlatformManager>();
if (platform != null) { if (platform != null)
{
float step = platform.speed * Time.deltaTime * 10f; float step = platform.speed * Time.deltaTime * 10f;
rb.AddForce((pullObject.transform.position - transform.position) * step, ForceMode.Force); rb.AddForce((pullObject.transform.position - transform.position) * step, ForceMode.Force);
} }
@ -159,6 +161,15 @@ public class PlayerController : MonoBehaviour
pushObject = null; pushObject = null;
} }
} }
var distanceFromYAxis = new Vector2(rb.position.x, rb.position.y).magnitude;
if (distanceFromYAxis > maxDistanceFromCenterLine)
{
Debug.Log("Player fell out of map.");
rb.velocity = Vector3.zero;
Physics.gravity = -Vector3.up * 9.81f;
UnityEngine.SceneManagement.SceneManager.LoadScene(0);
}
} }
void OnCollisionExit(Collision other) void OnCollisionExit(Collision other)
@ -219,7 +230,8 @@ public class PlayerController : MonoBehaviour
Vector3 gDirection = -other.GetContact(0).normal; Vector3 gDirection = -other.GetContact(0).normal;
PlatformManager platform = other.gameObject.GetComponent<PlatformManager>(); PlatformManager platform = other.gameObject.GetComponent<PlatformManager>();
if (platform != null) { if (platform != null)
{
switch (platform.type) switch (platform.type)
{ {
case PlatformManager.PlatformType.Push: case PlatformManager.PlatformType.Push: