Hello guys,
I’m sorry for bother you with “maybe” stupid question but I couldn’t find an answer.
So I’m about to make a soccer game but I have a little problem with Score counter.
I have a Ball Script which count a scores for me however I would like to transfer it to another empty separated gameObject with script called GameController. - I mean that separated gameobject GameController will count all scores after Ball collides with Nets.
I tried to call function OnTriggerEnter2D on GameController script however It didn’t worked. So I think I need some help with that.
Ball script :
void OnTriggerEnter2D(Collider2D trigger)
{
if (trigger.name == "playerNet")
{
enemyScore += 1;
enemyScoreText.GetComponent<Text>().text = enemyScore.ToString();
}
else if (trigger.name == "enemyNet")
{
playerScore += 1;
playerScoreText.GetComponent<Text>().text = playerScore.ToString();
}
if (trigger.gameObject.tag == "Goal")
{
sound[2].Play();
}
}
and I have one more question. so I have made a script for a delayed spawn with
void OnTriggerEnter2D(Collider2D trigger)
{
if (trigger.tag == "Puck")
{
Destroy(trigger.gameObject);
StartCoroutine("Respawn", 1f);
}
}
IEnumerator Respawn(float spawnDelay)
{
yield return new WaitForSeconds(spawnTime);
GameObject puck = Instantiate(Puck, spawnPoint.position, spawnPoint.rotation) as GameObject;
}
}
So everything works here great, ball is spawning as a clone from full loaded prefab, all components are assigned but the problem is that the ball(clone) count only 1 point for each of player not more.
That’s mean Ball doesn’t count more than 1:1…
Thanks for your help guys ! I appreciate that !