Question by
jlh_the_13th · Oct 12, 2020 at 09:43 AM ·
collidertriggerplayerdamage
Apply more damage over time?,How can I apply more damage over time?
I'm trying to see if I can add more, or simply double the amount of damage to the Player if they stand in the Fire for too long, similar to the acid spit from the Spitter in L4D2. I'm trying to see if I can apply more damage over time if my player stands in the fire for too long, i.e. 2, 4, 8, 16 and so on. Here is the current code as is:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PillarofFlame : MonoBehaviour { private HealthComp playerHC; private bool inFlames = false; private float burnTimer = 0f;
private void Start()
{
playerHC = GameObject.Find("Player").GetComponent<HealthComp>();
}
private void Update()
{
if (inFlames)
{
burnTimer = burnTimer - Time.deltaTime;
if(burnTimer <= 0)
{
playerHC.TakeDamage(17);
burnTimer = 1f;
}
}
}
private void OnTriggerEnter(Collider other)
{
if(other.tag == "Player")
{
inFlames = true;
}
}
private void OnTriggerExit(Collider other)
{
if(other.tag == "Player")
{
inFlames = false;
}
}
}
Comment