I have a script about GUIText.
public GUIText Enemyhealth;
private int EnemyH = 300;
private float distance = 2f;
Start {
Enemyhealth.text = " " + EnemyH;
}
Update {
if (Vector.Distance(transform.position, Vector.zero) < distance)
{
EnemyH = EnemyH - 50;
Enemyhealth.text = " " + EnemyH;
}
And it works perfectly - when both Enemyhealth ( GUIText object ) and object ( to which the script is attached to ) are on the scene.
But when i try to simply add
“GUIText EnemyHealth = Instantiate ( Enemyhealth ) as GUIText;”
trying to actually instantiate both GUIText and the object ( to which script is attached to ), it don’t work.
-
It shows GUIText , but with a state from the last play before. If the last time i played it was 250, then only the next time i play it shows 250.
-
And it don’t change the value in the game itself. If 250 should become 200, it stills shows 250, while in prefab it actually changed to 200. But the change itself will be shown only the next time i play. Without changing it in play mode at all.
So, as i said, it works perfectly when both GUIText object and the object ( to which scrpit is attached to ) are in the scene, but it’s broken when they are instantiated. Why?