-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerLife.cs
More file actions
46 lines (37 loc) · 996 Bytes
/
Copy pathPlayerLife.cs
File metadata and controls
46 lines (37 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerLife : MonoBehaviour
{
private Rigidbody2D rb;
private Animator anim;
[SerializeField] private AudioSource deathSoundEffect;
private void Start()
{
anim = GetComponent<Animator>();
rb = GetComponent<Rigidbody2D>();
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Trap"))
{
Die();
}
else if (collision.gameObject.CompareTag("Weak point"))
{
Die();
}
}
// trigger peux etre trouver dans la fenetre animator
private void Die()
{
deathSoundEffect.Play();
rb.bodyType = RigidbodyType2D.Static;
anim.SetTrigger("death");
}
private void RestartLevel()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}