So basically i have beam of lightning (it’s constant a beam and it will last as long as the input of the mouse) I need to make it so that the beam deals a certain amount of damage over time. By that I mean that when the enemy stands in the beam it will recieve damage and keep recieving damage as long as he stands in it. I don’t even know where to start. I don’t need any player health just the enemy and how to deal it to him. I know this is a really big question but I would really really appreciate it if anyone could help me with this.
I’d think of something like a collider and if a enemy enters it it will trigger and deal damage, I have no idea if that will even work.
Thank you!
There are a few ways to do this, my first attempt put the script on the beam, but it had to find out which enemy was in the beam and subtract his health. Worked for one enemy but got messy if more than one enemy in the beam. So I did it this way. First the beam needs a collider, but make it a trigger. Even though it triggers nothing, the enemies still need to be able to be inside of it. Next, tag the beam “Beam”. The enemy also needs to have a trigger collider on him for this script to work. It is his trigger that the beam is entering. You also need a health script on the enemy ( which I assume you have already) then add these lines of code to his health script;
public float beamDamage = .15f;
public float startingHealth = 100;
public float currentHealth;
void Start(){
currentHealth = startingHealth;
}
void OnTriggerStay(Collider other) {
if(other.tag == "Beam")
TakeDamage (beamDamage);
}
}
public void TakeDamage (float amount)
{
currentHealth -= amount;
}
}