Cant call void function from another script
Hello, i have void RegenerateDmg(int Dmg) in another script. I want to use it in script so i'm using PlayerHp(script name) ph; And i'm using it in void Use() which i use it in Button UI. It seems that i cant use it in void Use() but i can use it in Update(). I want when i'm pressing button i can call void Use() which has void RegenerateDmg(int Dmg).
public class PlayerHP : MonoBehaviour
{
public int maxhp = 100;
public int currenthp;
public healthbar hp;
public GameObject UseObject;
void Start()
{
currenthp = maxhp;
hp.SetHP(maxhp);
}
void Update()
{
if(Input.GetKeyDown(KeyCode.Space))
{
print("dmg");
TakeDmg(10);
}
GameOver();
}
public void TakeDmg(int Dmg)
{
currenthp -= Dmg;
hp.SetHP(currenthp);
}
void GameOver()
{
if(currenthp<=0)
{
SceneManager.LoadScene(2);
}
}
public void RegenerateDmg(int Dmg)
{
currenthp += Dmg;
hp.SetHP(currenthp);
}
}
public class UseItem : MonoBehaviour
{
public PlayerHP ph;
public void Use()
{
if (gameObject.name == "Apple Button(Clone)")
{
ph.RegenerateDmg(20);
}
Destroy(gameObject);
}
}
Comment