playerlives
added basic playerlives counting for the free-for-all gamemode. Sstill needs to be implemented
This commit is contained in:
@@ -38,6 +38,20 @@ public class Damageable : MonoBehaviour
|
|||||||
}
|
}
|
||||||
damage += actualForce;
|
damage += actualForce;
|
||||||
damage = Mathf.Clamp(damage, 0f, maxDamage);
|
damage = Mathf.Clamp(damage, 0f, maxDamage);
|
||||||
|
|
||||||
|
if (damage >= maxDamage)
|
||||||
|
{
|
||||||
|
Die();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Die()
|
||||||
|
{
|
||||||
|
PlayerLives playerLives = GetComponent<PlayerLives>(); //add death animation trigger
|
||||||
|
if (playerLives != null)
|
||||||
|
{
|
||||||
|
playerLives.PlayerDied();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResetDamage()
|
public void ResetDamage()
|
||||||
|
|||||||
43
Assets/Scripts/PlayerLives.cs
Normal file
43
Assets/Scripts/PlayerLives.cs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class PlayerLives : MonoBehaviour
|
||||||
|
{
|
||||||
|
public int maxLives = 3;
|
||||||
|
public int currentLives;
|
||||||
|
public string gameMode = "free-for-all";
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
if (gameMode == "free-for-all")
|
||||||
|
{
|
||||||
|
currentLives = maxLives;
|
||||||
|
}
|
||||||
|
else //add more gamemodes and their lives here
|
||||||
|
{
|
||||||
|
currentLives = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void PlayerDied()
|
||||||
|
{
|
||||||
|
if (gameMode == "free-for-all")
|
||||||
|
{
|
||||||
|
currentLives--;
|
||||||
|
if (currentLives <= 0)
|
||||||
|
{
|
||||||
|
//add Game over sequence;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RespawnPlayer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void RespawnPlayer()
|
||||||
|
{
|
||||||
|
RespawnOnTriggerEnter respawnScript = GetComponent<RespawnOnTriggerEnter>();
|
||||||
|
if (respawnScript != null)
|
||||||
|
{
|
||||||
|
transform.position = respawnScript.spawnPoint;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
2
Assets/Scripts/PlayerLives.cs.meta
Normal file
2
Assets/Scripts/PlayerLives.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 207bf152528fc954cb2c73fd9d62c9b0
|
||||||
Reference in New Issue
Block a user