Player health lose when player touch object only if the object is active. But didn’t work somehow…
public class LaserFlickering : MonoBehaviour
{
public GameObject laser; public float delay; public float maxDelay;
void Update()
{
if (delay < maxDelay)
{
delay += Time.deltaTime;
}
else
{
delay = 0;
laser.SetActive(!laser.activeSelf);
}
}
public void OnTriggerEnter2D(Collider2D col)
{
HealthControl.health -= 1;
}
}