Can't change text in canvas from a prefab
(I'm new to Unity so this fix could be very simple) I'm creating a minigame where when objects are pushed off an area, they disappear and the score is increased. My variable for tracking whenever an enemy disappears is on a script attached to the enemy prefab. However, because this is a script on a prefab, Unity won't allow me to reference text from the scene. I've tried a lot of different ways to get the text in the scene to change, but nothing is working for me. Any solutions? The base code for the enemies:
float pointX;
float pointY;
public int enemiesKilled = 0;
void Update()
{
pointX = gameObject.transform.position.x;
pointY = gameObject.transform.position.y;
if (pointX < -10.4 || pointX > 10.4 || pointY < -10.4 || pointY > 10.4)
{
enemiesKilled += 1;
Debug.Log(enemiesKilled);
//where the code that changes the text should be
Destroy(gameObject);
}
}
} Thanks!
Your answer
Follow this Question
Related Questions
My score system doesn't display or work? Please help me! 1 Answer
Highscore and PlayerPrefs unity C# 1 Answer
How do I make the Score system work? 1 Answer
Question concerning pacman tutorial. 0 Answers
how to create a score multiplier? 0 Answers