-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Emit death when dying #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,18 +9,18 @@ public class PlayerHealth : MonoBehaviour | |||||||||||||||||||||||||||||||||||||||||||||
| public int maxHealth = 5; // Points de vie maximum | ||||||||||||||||||||||||||||||||||||||||||||||
| private int currentHealth; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| public GameObject heartPrefab; | ||||||||||||||||||||||||||||||||||||||||||||||
| public Transform healthBar; | ||||||||||||||||||||||||||||||||||||||||||||||
| public GameObject heartPrefab; | ||||||||||||||||||||||||||||||||||||||||||||||
| public Transform healthBar; | ||||||||||||||||||||||||||||||||||||||||||||||
| private List<GameObject> hearts = new List<GameObject>(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| private SocketIOUnity clientSocket; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| public GameObject deadCanvas; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| void Start() | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| currentHealth = maxHealth; | ||||||||||||||||||||||||||||||||||||||||||||||
| UpdateHealthBar(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -53,32 +53,32 @@ public void Heal(int amount) | |||||||||||||||||||||||||||||||||||||||||||||
| UpdateHealthBar(); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| async void SocketEmitter() | ||||||||||||||||||||||||||||||||||||||||||||||
| async void SocketEmitter() | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| await clientSocket.EmitAsync("rooms:end"); | ||||||||||||||||||||||||||||||||||||||||||||||
| await clientSocket.EmitAsync("rooms:death"); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| void Die() | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (deadCanvas != null && !deadCanvas.activeSelf) | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| SocketEmitter(); | ||||||||||||||||||||||||||||||||||||||||||||||
| deadCanvas.SetActive(true); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| GetComponent<PlayerMovement>().enabled = false; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
62
to
+70
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Vérification nécessaire de clientSocket Il faut vérifier que clientSocket n'est pas null avant d'appeler SocketEmitter pour éviter une NullReferenceException. void Die()
{
if (deadCanvas != null && !deadCanvas.activeSelf)
{
- SocketEmitter();
+ if (clientSocket != null)
+ SocketEmitter();
+ else
+ Debug.LogWarning("Socket client non initialisé");
deadCanvas.SetActive(true);
}
GetComponent<PlayerMovement>().enabled = false;
}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| void UpdateHealthBar() | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| foreach (GameObject heart in hearts) | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| Destroy(heart); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| hearts.Clear(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+74
to
+81
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Optimisation possible avec l'Object Pooling La création et destruction répétée des cœurs pourrait être optimisée en utilisant l'Object Pooling, une pratique recommandée dans Unity pour les objets fréquemment instanciés/détruits. Je peux vous aider à implémenter un système d'Object Pooling si vous le souhaitez. |
||||||||||||||||||||||||||||||||||||||||||||||
| for (int i = 0; i < currentHealth; i++) | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| GameObject newHeart = Instantiate(heartPrefab, healthBar); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -94,7 +94,7 @@ void OnCollisionEnter2D(Collision2D collision) | |||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| public void ReturnToMenu() | ||||||||||||||||||||||||||||||||||||||||||||||
| public void ReturnToMenu() | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| GameObject socket = GameObject.FindWithTag("Temporary"); | ||||||||||||||||||||||||||||||||||||||||||||||
| if (socket != null) Destroy(socket.gameObject); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ajout nécessaire de la gestion des erreurs
L'émission de socket devrait inclure une gestion des erreurs pour éviter les problèmes de connexion silencieux.
async void SocketEmitter() { - await clientSocket.EmitAsync("rooms:death"); + try { + await clientSocket.EmitAsync("rooms:death"); + } catch (System.Exception e) { + Debug.LogError($"Erreur lors de l'émission de l'événement death: {e.Message}"); + } }📝 Committable suggestion