Cosmic Strike
Cargando...
Buscando...
Nada coincide
PowerUpExtraLife.cs
Ir a la documentación de este archivo.
1
8
9
using
UnityEngine;
10
15
[RequireComponent(typeof(Collider2D))]
16
public
class
PowerUpExtraLife
: MonoBehaviour
17
{
18
// ========== PARÁMETRO CONFIGURABLE ==========
19
23
[Header(
"Cuántas vidas extra da"
)]
24
[Tooltip(
"Cantidad de salud que se suma al recoger"
)]
25
public
int
extraHealth
= 1;
26
27
// ========== DETECCIÓN DE COLISIÓN ==========
28
34
private
void
OnTriggerEnter2D
(Collider2D other)
35
{
36
if
(!other.CompareTag(
"Player"
))
return
;
37
38
// 1) Obtenemos el componente Health del jugador
39
var health = other.GetComponent<
Health
>();
40
if
(health !=
null
)
41
{
42
// 2) Sanamos al jugador
43
Debug.Log(
"llamando a añadir vida"
);
44
health.AddHealth(
extraHealth
);
45
}
46
else
47
{
48
Debug.LogWarning(
"PowerUpExtraLife: Player no tiene componente Health."
);
49
}
50
51
// 3) Destruye el Power-Up
52
Destroy(gameObject);
53
}
54
}
Health
Componente que gestiona la salud de un objeto. Permite recibir daño y ser destruido al llegar a cero....
Definition
Health.cs:17
PowerUpExtraLife
Componente que define un Power-Up que otorga salud adicional al jugador. Al colisionar con el jugador...
Definition
PowerUpExtraLife.cs:17
PowerUpExtraLife.extraHealth
int extraHealth
Cantidad de salud que se añade al jugador al recoger el Power-Up.
Definition
PowerUpExtraLife.cs:25
PowerUpExtraLife.OnTriggerEnter2D
void OnTriggerEnter2D(Collider2D other)
Método llamado automáticamente cuando otro objeto con un Collider2D entra en el trigger....
Definition
PowerUpExtraLife.cs:34
Assets
Scripts
PowerUps
PowerUpExtraLife.cs
Generado por
1.13.2