I'm a beginner and I need some help to pass a function located on one script to another one so I can use his value. First I have a class called Enemies where I count the enmies killed and then I have a script that allows the player to go to the next level using a door. So I want to use the counter to "open" the door when the player has killed X number of enemies. How can I pass the counter value? Thanks.
public class Enemies : MonoBehaviour {
public GameObject enemy;
public int health = 100;
public int deathCounter = 0;
public void TakeDamage(int damage)
{
health -= damage;
if (health <= 0)
{
Destroy(enemy);
deathCounter++;
}
}
}
public class nextlevel : MonoBehaviour {
public Enemies deadcounter;
public int index;
private void OnTriggerEnter2D(Collider2D other)
{
if(other.CompareTag("Player"))
{
SceneManager.LoadScene(1);
}
}
}