Linking prefab with UI text

hi guys, how are u doin??

I made some modifications to the game by myself and I got a big problem trying to link a prefab (the prefab or a UI text where I wanted to put the score - destroyed blocks and remaining blocks) and the LevelManager

at the beggining I tried to copy the course code using levelManager = GameObject.FindObjectOfType(); but this didnt work with the UI (GameObject.FindObjectOfType() this instruccion gave me problems) so this is what I did:

I made a new script for the UI text simply as this:

using UnityEngine; using UnityEngine.UI; using System.Collections;

public class Score : MonoBehaviour {

public string score_text="";
public Text score;

void Update () {

    score.text = score_text;


here what I do is in every update, i put in the UI text the values of a public string I made

and then from the level manager I access to this public variable and modify it

public Score score;

score = GameObject.FindObjectOfType();
score.score_text = number_of_destroyed_blocks.ToString() + “/” + number_of_remaining_blocks.ToString();

and this works, the prefab works, and I can add the prefab form one scene to the other

I dunno if this is the correct way of doing this, but at least i found a solution so maybe this could help you too

Privacy & Terms