public GameObject nextPlayer;// Drag & Drop the prefab with the Ghost script attached to it
void OnTriggerEnter(Collider other)
{
if (other.tag == "Egg")
{
scoreScript.updateScore();
Destroy(other.gameObject); // Or whatever way you want to remove the coin.
if (scoreScript.score == 1)
{
(Instantiate(FEggPrefab, Spawn.position, Spawn.rotation)).SetTarget(gameObject, 8);
}
else if (scoreScript.score == 2)
{
nextPlayer = GameObject.FindGameObjectsWithTag("Player")[1];
(Instantiate(FEggPrefab, Spawn.position, Spawn.rotation)).SetTarget(nextPlayer, 8);
}
else
{
nextPlayer = GameObject.FindGameObjectsWithTag("Player")[2];
(Instantiate(FEggPrefab, Spawn.position, Spawn.rotation)).SetTarget(nextPlayer, 8);
}
}
else if (other.tag == "EndPoint")
{
PlayerPrefs.SetInt("TotalEggs", scoreScript.score + PlayerPrefs.GetInt("TotalEggs"));
gameController.CompleteLevel();
}
else
{
}
}