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:
@@ -476,6 +476,8 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
finished: 0
|
||||
respawn: 0
|
||||
lives: 3
|
||||
maxSpeed: 25
|
||||
acceleration: 0.5
|
||||
friction: 0.1
|
||||
@@ -570,7 +572,7 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1644583839}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 5, z: 0}
|
||||
m_LocalPosition: {x: 0, y: 2, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children:
|
||||
- {fileID: 1573414423}
|
||||
|
||||
@@ -1265,7 +1265,7 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 741217452}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 5, z: 0}
|
||||
m_LocalPosition: {x: 0, y: 2, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children:
|
||||
- {fileID: 615882419}
|
||||
@@ -1284,6 +1284,9 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 83127dd120c01de45954b99cc4d669a5, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
finished: 0
|
||||
respawn: 0
|
||||
lives: 3
|
||||
maxSpeed: 25
|
||||
acceleration: 0.5
|
||||
friction: 0.1
|
||||
|
||||
@@ -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,8 +80,6 @@ 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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,9 @@ EditorBuildSettings:
|
||||
- enabled: 1
|
||||
path: Assets/Scenes/Hub World.unity
|
||||
guid: 9fc0d4010bbf28b4594072e72b8655ab
|
||||
- enabled: 1
|
||||
path: Assets/Scenes/Floor Level.unity
|
||||
guid: 1677949d058a3674f9e975f034bdb9a5
|
||||
m_configObjects:
|
||||
com.unity.input.settings: {fileID: 11400000, guid: 5dbe934aa009ccc4591ccf96f49a3d48,
|
||||
type: 2}
|
||||
|
||||
Reference in New Issue
Block a user