0
votes

Using Unity 5.0.2f1 for Mac.

Created a UI Text object (called LifeCountUI) in the scene. Then, on my Player's script (attached to my Player GameObject), I have the following field serialized:

[SerializeField]
public Text LifeCountText;

This Player GameObject is also a prefab.

My intention was to drag the LifeCountUI in the inspector to the serialized field on the Player GameObject. However, Unity does not allow me to do this when I select the Player prefab.

It only works, if I drag an instance of the Player prefab on to the scene, and then drag the LifeCountUI to the field (but obviously, that is not the prefab).

Am I doing something wrong here? I essentially want to have the ability to control the text field from the prefab instance.

1

1 Answers

1
votes

Have a look at what gurus say about it in famouse 50 Tips for Working with Unity (Best Practices) article:

  1. Link prefabs to prefabs; do not link instances to instances. Links to prefabs are maintained when dropping a prefab into a scene; links to instances are not. Linking to prefabs whenever possible reduces scene setup, and reduce the need to change scenes.

This is one of reason you are unable to maintain a reference.