- Home /
Damage over time while colliding.
I am really sorry if this doesn't end up very clear, I tend to avoid using forums because I never know how to frame my questions.
The situation is that I have two objects; a Player, with a stat called Fear that by default is set to 0, and an Enemy that has a collider covering an area surrounding it.
Essentially what I am trying to do is raise the value of the Player's fear by 1/sec while in close proximity to the Enemy.
I am still very new to coding, and am struggling to understand how scripts communicate with each other.
If this is not enough information, please let me know what else you need.
Answer by Dracolyte · Nov 29, 2020 at 08:55 AM
I dont know if my script work but you put this script on you player and you need to give the enemy the "Enemy" tag. Then It should increase the fear if the player stays in collision with the enemy. Im new to coding too but I still can help somehow, right?
float Fear = 0f;
float FearPerSec = 1f;
void IncreaseFear ()
{
Fear += FearPerSec * Time.deltaTime;
}
private void OnCollisionStay(Collision other)
{
If (other.collider.CompareTag("Enemy"))
{
IncreaseFear();
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How can i get harmed and healed by diferent game objects 0 Answers
How to apply damage without Raycast 1 Answer
Damage on collision with player.. 1 Answer
Making the collider change after being instantiate 2 Answers