Answer the question
In order to leave comments, you need to log in
How to describe first-aid kits correctly in the player's script so that they add health?
Create a new type of level bonus - first aid kits, which can store different amounts of healing. When a first aid kit comes into contact with any object containing a Health component, the first aid kit should add an amount of healing to the object and disappear from the game scene.
The player contains a Health component. I need to call the method in the player script
public void SetHealth(int bonusHealth)
{
health+= bonusHealth;
}
public void OnTriggerEnter2D(Collider2D col)
{
if(col.gameObject.CompareTag("Tablet"))
{
Destroy(col.gameObject);
}
}
Answer the question
In order to leave comments, you need to log in
Maybe you need to call a method in a trigger? It won't work just by writing it:
public void SetHealth(int bonusHealth)
{
health+= bonusHealth;
}
public void OnTriggerEnter2D(Collider2D col)
{
if(col.gameObject.CompareTag("Tablet"))
{
Destroy(col.gameObject);
SetHealth(10);//Вместо 10 укажи нужное тебе бонусное хп.
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question