I’m creating some sort of score system. There’s a GUI Text which will show you your score. Every time you hit a triggered, invisible object, your score will raise by one. However, if I use the function “OnTriggerEnter” it gets called at least 14 times. It gets called in the time you are IN the object. I believe OnTriggerStay should function like that.
Anyway, here is my code:
public static int pScore = 0;
public GUIText ScoreText;
void OnTriggerEnter2D(Collider2D collider)
{
if (collider.gameObject)
{
pScore++;
ScoreText.text = "" + pScore;
print("Test");
}
}
FYI OnTriggerEnter is called only once by default, when ever some thing enter the trigger. So you don’t have to worry about calling it only once. Only OnTriggerStay is called repetitively untill the object leaves the trigger.