From 9c284d32e122f223166d3d1f340cfd853c70359f Mon Sep 17 00:00:00 2001 From: Eryck Kawa <108304916+EryckKawa@users.noreply.github.com> Date: Tue, 9 Jul 2024 08:31:21 -0300 Subject: [PATCH 1/3] add script player status --- Assets/Scripts/Player/PlayerStats.cs | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Assets/Scripts/Player/PlayerStats.cs diff --git a/Assets/Scripts/Player/PlayerStats.cs b/Assets/Scripts/Player/PlayerStats.cs new file mode 100644 index 0000000..8c7995e --- /dev/null +++ b/Assets/Scripts/Player/PlayerStats.cs @@ -0,0 +1,6 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[SerializeField] private float playerHealth; +[SerializeField] private float damagePlayer; \ No newline at end of file From d64a5bf8013c7f15601c7374a18f432a9e5932bf Mon Sep 17 00:00:00 2001 From: Eryck Kawa <108304916+EryckKawa@users.noreply.github.com> Date: Tue, 9 Jul 2024 08:44:48 -0300 Subject: [PATCH 2/3] update playerstats script --- Assets/Scripts/Player/PlayerStats.cs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/Player/PlayerStats.cs b/Assets/Scripts/Player/PlayerStats.cs index 8c7995e..e7b370f 100644 --- a/Assets/Scripts/Player/PlayerStats.cs +++ b/Assets/Scripts/Player/PlayerStats.cs @@ -2,5 +2,27 @@ using System.Collections.Generic; using UnityEngine; -[SerializeField] private float playerHealth; -[SerializeField] private float damagePlayer; \ No newline at end of file +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!"); + } + } +} From 899d013735b70b7553385d4f497c8f4f35241767 Mon Sep 17 00:00:00 2001 From: Eryck Kawa Date: Thu, 11 Jul 2024 09:31:21 -0300 Subject: [PATCH 3/3] add consumivel e forma de recuperar vida em player stats --- Assets/Scenes/Torre - Felipe.unity | 11 ++--- Assets/Scripts/Consumables.meta | 8 +++ Assets/Scripts/Consumables/HealthOrb.cs | 18 +++++++ Assets/Scripts/Consumables/HealthOrb.cs.meta | 11 +++++ Assets/Scripts/Player/PlayerStats.cs | 51 ++++++++++++-------- Assets/Scripts/Player/PlayerStats.cs.meta | 11 +++++ 6 files changed, 85 insertions(+), 25 deletions(-) create mode 100644 Assets/Scripts/Consumables.meta create mode 100644 Assets/Scripts/Consumables/HealthOrb.cs create mode 100644 Assets/Scripts/Consumables/HealthOrb.cs.meta create mode 100644 Assets/Scripts/Player/PlayerStats.cs.meta diff --git a/Assets/Scenes/Torre - Felipe.unity b/Assets/Scenes/Torre - Felipe.unity index f127ed1..f4ce865 100644 --- a/Assets/Scenes/Torre - Felipe.unity +++ b/Assets/Scenes/Torre - Felipe.unity @@ -12486,11 +12486,6 @@ Transform: m_CorrespondingSourceObject: {fileID: 1149450743610261583, guid: dc02f77b0506f764c9d22c61c681c4af, type: 3} m_PrefabInstance: {fileID: 1746705694} m_PrefabAsset: {fileID: 0} ---- !u!4 &1762591494 stripped -Transform: - m_CorrespondingSourceObject: {fileID: 6433677090840053048, guid: 19126af9e3b37894aa7f8924b2916d27, type: 3} - m_PrefabInstance: {fileID: 2135270840} - m_PrefabAsset: {fileID: 0} --- !u!1001 &1781144544 PrefabInstance: m_ObjectHideFlags: 0 @@ -15355,7 +15350,11 @@ PrefabInstance: - target: {fileID: 613842560230377664, guid: 19126af9e3b37894aa7f8924b2916d27, type: 3} propertyPath: interactorSource value: - objectReference: {fileID: 1762591494} + objectReference: {fileID: 1487666422} + - target: {fileID: 3122378250214386190, guid: 19126af9e3b37894aa7f8924b2916d27, type: 3} + propertyPath: gameInput + value: + objectReference: {fileID: 1606203397} - target: {fileID: 4793283505566672030, guid: 19126af9e3b37894aa7f8924b2916d27, type: 3} propertyPath: player value: diff --git a/Assets/Scripts/Consumables.meta b/Assets/Scripts/Consumables.meta new file mode 100644 index 0000000..8ddbf4e --- /dev/null +++ b/Assets/Scripts/Consumables.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 42327c21ddd584b46944a137ef332b5b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Consumables/HealthOrb.cs b/Assets/Scripts/Consumables/HealthOrb.cs new file mode 100644 index 0000000..493b25d --- /dev/null +++ b/Assets/Scripts/Consumables/HealthOrb.cs @@ -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(); + if (playerStatus != null) + { + playerStatus.RestoreHealth(restoreAmount); + Destroy(gameObject); + } + } +} diff --git a/Assets/Scripts/Consumables/HealthOrb.cs.meta b/Assets/Scripts/Consumables/HealthOrb.cs.meta new file mode 100644 index 0000000..0b7a0e0 --- /dev/null +++ b/Assets/Scripts/Consumables/HealthOrb.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bb874ba72fe954b42a28bf679a3ecfa8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Player/PlayerStats.cs b/Assets/Scripts/Player/PlayerStats.cs index e7b370f..a037a42 100644 --- a/Assets/Scripts/Player/PlayerStats.cs +++ b/Assets/Scripts/Player/PlayerStats.cs @@ -4,25 +4,38 @@ 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 + [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); - } - } + 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}"); + } - public void TakeDamage(float damage) - { - playerHealth -= damage; - Debug.Log($"Player took {damage} damage. Current health: {playerHealth}"); - - if (playerHealth <= 0) - { - Debug.Log("Player has died!"); - } - } } diff --git a/Assets/Scripts/Player/PlayerStats.cs.meta b/Assets/Scripts/Player/PlayerStats.cs.meta new file mode 100644 index 0000000..22a455e --- /dev/null +++ b/Assets/Scripts/Player/PlayerStats.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a9b2612d3c901864992b1b923f465c85 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: