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_TransformParent: {fileID: 0}
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}
propertyPath: m_Name
value: Player

View File

@ -4,6 +4,7 @@ using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float maxDistanceFromCenterLine;
[Header("Move")]
public float speed = 7.5f;
public float maxSpeed = 15.0f;
@ -115,7 +116,7 @@ public class PlayerController : MonoBehaviour
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;
}
else
@ -136,7 +137,8 @@ public class PlayerController : MonoBehaviour
if (pullObject != null)
{
PlatformManager platform = pullObject.GetComponent<PlatformManager>();
if (platform != null) {
if (platform != null)
{
float step = platform.speed * Time.deltaTime * 10f;
rb.AddForce((pullObject.transform.position - transform.position) * step, ForceMode.Force);
}
@ -159,6 +161,15 @@ public class PlayerController : MonoBehaviour
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)
@ -219,7 +230,8 @@ public class PlayerController : MonoBehaviour
Vector3 gDirection = -other.GetContact(0).normal;
PlatformManager platform = other.gameObject.GetComponent<PlatformManager>();
if (platform != null) {
if (platform != null)
{
switch (platform.type)
{
case PlatformManager.PlatformType.Push: