add: Player script with hp
add: player death handling and OnLevelFailed event
This commit is contained in:
@@ -251,6 +251,7 @@ GameObject:
|
||||
- component: {fileID: 7857072580326449292}
|
||||
- component: {fileID: 1437407097293080706}
|
||||
- component: {fileID: 8985924327125149956}
|
||||
- component: {fileID: 3824427059318413399}
|
||||
- component: {fileID: 397169322893853401}
|
||||
- component: {fileID: 1198108720433238150}
|
||||
- component: {fileID: 3263211181679880648}
|
||||
@@ -384,6 +385,20 @@ Rigidbody:
|
||||
m_Interpolate: 0
|
||||
m_Constraints: 80
|
||||
m_CollisionDetection: 0
|
||||
--- !u!114 &3824427059318413399
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 9016311960615966999}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: f9b2638aeb16f76429ff062f38f6d0be, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
maxHp: 100
|
||||
hp: 0
|
||||
--- !u!114 &397169322893853401
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class EyeEnemy : Enemy
|
||||
{
|
||||
public float _hp = 100;
|
||||
|
||||
void Start() {
|
||||
hp = _hp;
|
||||
}
|
||||
|
||||
void Update() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48cddee1e4d4837418957a7b4e6315c8
|
||||
@@ -4,8 +4,7 @@ using UnityEngine.SceneManagement;
|
||||
public class DeployController : MonoBehaviour
|
||||
{
|
||||
public void Start() {
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
GameController.SetCursorState(true);
|
||||
}
|
||||
|
||||
public void Deploy(string sceneName) {
|
||||
|
||||
@@ -3,11 +3,13 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class GameController : MonoBehaviour
|
||||
{
|
||||
public static GameController i;
|
||||
public SceneAsset deployScene;
|
||||
public List<LevelInfo> levels;
|
||||
public List<EnemyInfo> enemies;
|
||||
|
||||
@@ -47,6 +49,10 @@ public class GameController : MonoBehaviour
|
||||
|
||||
}
|
||||
|
||||
public void OnLevelFailed(string sceneName, float timeSpent) {
|
||||
|
||||
}
|
||||
|
||||
EnemyInfo SelectEnemyWeighted() {
|
||||
float sumWeights = enemies.Sum(enemy => enemy.weight);
|
||||
float r = Random.Range(0, sumWeights);
|
||||
@@ -57,6 +63,15 @@ public class GameController : MonoBehaviour
|
||||
}
|
||||
return enemies[^1];
|
||||
}
|
||||
|
||||
public void LoadDeployScene() {
|
||||
SceneManager.LoadScene(deployScene.name);
|
||||
}
|
||||
|
||||
public static void SetCursorState(bool locked) {
|
||||
Cursor.lockState = locked ? CursorLockMode.Locked : CursorLockMode.None;
|
||||
Cursor.visible = !locked;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class LevelController : MonoBehaviour
|
||||
{
|
||||
public SceneAsset deployScene;
|
||||
public List<SpawnPointInfo> spawnPoints;
|
||||
|
||||
List<Enemy> aliveEnemies;
|
||||
@@ -33,10 +31,15 @@ public class LevelController : MonoBehaviour
|
||||
public void Update() {
|
||||
if (aliveEnemies.All(enemy => enemy == null)) {
|
||||
GameController.i.OnLevelClear(SceneManager.GetActiveScene().name, timeSpent);
|
||||
SceneManager.LoadScene(deployScene.name);
|
||||
GameController.i.LoadDeployScene();
|
||||
}
|
||||
timeSpent += Time.deltaTime;
|
||||
}
|
||||
|
||||
public void OnPlayerDie() {
|
||||
GameController.i.OnLevelFailed(SceneManager.GetActiveScene().name, timeSpent);
|
||||
GameController.i.LoadDeployScene();
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
|
||||
@@ -12,8 +12,7 @@ public class CameraMovement : MonoBehaviour
|
||||
|
||||
void Start() {
|
||||
cam = GetComponentInChildren<Camera>();
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = false;
|
||||
GameController.SetCursorState(true);
|
||||
}
|
||||
|
||||
void Update() {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Player : MonoBehaviour
|
||||
{
|
||||
public float maxHp = 100;
|
||||
|
||||
[SerializeField] float hp;
|
||||
|
||||
void Start() {
|
||||
hp = maxHp;
|
||||
}
|
||||
|
||||
public void DealDamage(float damage) {
|
||||
hp -= damage;
|
||||
if (hp <= 0) {
|
||||
FindAnyObjectByType<LevelController>().OnPlayerDie();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f9b2638aeb16f76429ff062f38f6d0be
|
||||
Reference in New Issue
Block a user