Adding respawning and a lives count. Once lives count reaches zero you are kicked back to hub world. Hub world also has respawning

This commit is contained in:
Gregory Campbell
2020-01-11 14:04:14 -05:00
parent 406a39655d
commit 05632bf0b7
5 changed files with 47 additions and 20 deletions
+19 -7
View File
@@ -1,4 +1,5 @@
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;
// This script moves the character controller forward
@@ -13,6 +14,8 @@ public class PlayerController : MonoBehaviour
CapsuleCollider capsule;
public bool finished = false;
public bool respawn = false;
public int lives = 3;
public float maxSpeed;
public float acceleration;
public float friction;
@@ -77,9 +80,7 @@ public class PlayerController : MonoBehaviour
finished = true;
respawnTime = Time.time;
} else {
finished = false;
}
}
}
@@ -92,6 +93,20 @@ public class PlayerController : MonoBehaviour
moveDirection = Vector3.ClampMagnitude(moveDirection, 1.0f);
moveDirection.y = yStore;
if(transform.position.y < -20.0f)
{
respawn = true;
respawnTime = Time.time;
if (SceneManager.GetActiveScene().name == "Hub World")
{
transform.position = new Vector3(0, 2, 0);
transform.Rotate(0.0f, 0.0f, 0.0f, Space.Self);
}
}
if (jump >= 2)
{
if(maxSpeed > maxSpeedStore/1.5f)
@@ -214,7 +229,6 @@ public class PlayerController : MonoBehaviour
if (characterController.collisionFlags == CollisionFlags.None)
{
wallRunning = false;
//finished = false;
wall = 0;
}
@@ -276,10 +290,8 @@ public class PlayerController : MonoBehaviour
velocity.z = velocity.z * Mathf.Abs(moveDirection.y);
}
Debug.Log("Current Position: " + transform.position);
// Move the controller
if(finished == false && respawnTime + tenthSec < Time.time)
if((finished == false || respawn == false) && respawnTime + tenthSec < Time.time)
{
characterController.Move(velocity * Time.deltaTime);
}
+18 -11
View File
@@ -1,6 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
[System.Serializable]
@@ -12,7 +13,6 @@ public class ProceduralGeneration : MonoBehaviour
public PlayerController script;
public GameObject[] obstacleList;
private bool worldBuild = false;
private int selection = 0;
// Start is called before the first frame update
@@ -21,10 +21,9 @@ public class ProceduralGeneration : MonoBehaviour
script = player.GetComponent<PlayerController>();
escalation = 1;
worldBuild = false;
script.lives = 3;
script.finished = false;
script.transform.position = new Vector3((50*escalation)+100, 2, (50*escalation)+100);
script.transform.Rotate(0.0f, 0.0f, 0.0f, Space.Self);
respawn();
script.pivot.transform.Rotate(0.0f, 225.0f, 0.0f, Space.Self);
levelBuild();
@@ -36,14 +35,25 @@ public class ProceduralGeneration : MonoBehaviour
if(script.finished == true)
{
respawn();
escalation++;
respawn();
levelBuild();
}
if(worldBuild == true)
if(script.respawn == true)
{
levelBuild();
respawn();
script.lives--;
script.respawn = false;
}
if(script.lives == 0)
{
script.lives = -1;
SceneManager.LoadScene("Hub World", LoadSceneMode.Single);
}
}
@@ -51,10 +61,8 @@ public class ProceduralGeneration : MonoBehaviour
void respawn()
{
Debug.Log("Sent: " + new Vector3((50*escalation)+100, 2, (50*escalation)+100));
script.transform.position = new Vector3((50*escalation)+100, 10, (50*escalation)+100);
script.transform.position = new Vector3((50*escalation)+100, 2, (50*escalation)+100);
script.transform.Rotate(0.0f, 0.0f, 0.0f, Space.Self);
worldBuild = true;
}
@@ -91,7 +99,6 @@ public class ProceduralGeneration : MonoBehaviour
Instantiate(obstacleList[0], new Vector3((50*escalation)+100, 0, (50*escalation)+100), Quaternion.identity);
Instantiate(obstacleList[1], new Vector3(-((50*escalation)+100), 0, -((50*escalation)+100)), Quaternion.identity);
worldBuild = false;
script.finished = false;
}