- Home /
The question is answered, right answer was accepted
prefab instance keeps its connection to script
I have a scene where I have a GUIText object
which I have linked to my character prefab
when I instantiate this in game it creates a clone
and the script doesn't work on the new object.
If I pause the game and drag the prefab onto the GUIText script again and run it it will work fine.
Is there something I need to be doing in my code to make sure I can keep this connection on any instances.
I have added the code it basically looks at the script PickupScore on my prefab which is what is losing it's connection
var player : PickupScore;
function Update()
{
GetComponent(GUIText).text = player.score.ToString();
Debug.Log("added value");
}
Thanks I ended up finding object by tag and pulling the script that way which seems to be working perfectly now
Answer by beelzeboss · Apr 08, 2013 at 12:58 PM
function Update()
{
var player = GameObject.FindWithTag("hamsterBall");
var newScore = player.GetComponent(PickupScore).scoreStr;
GetComponent(GUIText).text = newScore;
Debug.Log("added value");
}
Follow this Question
Related Questions
prefab instance keeps its connection to script 1 Answer
Accesing script from newly instantiated game object 1 Answer
Instantiate a 2d Pop up 1 Answer
Mesh and material disappear after CreatePrefab() in C# 1 Answer
Scrolling Text 1 Answer