-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from ES2-UFPI/eryckkawa#30
Finalizado sistema de dano
- Loading branch information
Showing
6 changed files
with
94 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class HealthOrb : MonoBehaviour | ||
{ | ||
[SerializeField] private float restoreAmount = 20f; | ||
|
||
private void OnTriggerEnter(Collider other) | ||
{ | ||
PlayerStatus playerStatus = other.GetComponent<PlayerStatus>(); | ||
if (playerStatus != null) | ||
{ | ||
playerStatus.RestoreHealth(restoreAmount); | ||
Destroy(gameObject); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class PlayerStatus : MonoBehaviour | ||
{ | ||
[SerializeField] private float playerHealth = 100f; // Valor inicial da saúde do jogador | ||
[SerializeField] private float damagePlayer = 10f; // Dano causado pelo jogador | ||
|
||
private void Update() | ||
{ | ||
if (Input.GetKeyDown(KeyCode.Space)) | ||
{ | ||
TakeDamage(damagePlayer); | ||
} | ||
} | ||
|
||
public void TakeDamage(float damage) | ||
{ | ||
playerHealth -= damage; | ||
Debug.Log($"Player took {damage} damage. Current health: {playerHealth}"); | ||
|
||
if (playerHealth <= 0) | ||
{ | ||
Debug.Log("Player has died!"); | ||
} | ||
} | ||
|
||
public void RestoreHealth(float health) | ||
{ | ||
playerHealth += health; | ||
|
||
if (playerHealth > 100f) | ||
{ | ||
playerHealth = 100f; | ||
} | ||
|
||
Debug.Log($"Player restored {health} health. Current health: {playerHealth}"); | ||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.