- Home /
Text UI field input doesn't get saved in my prefab
In my game's one of the prefab I have this below code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class monkeyscript : MonoBehaviour
{
public Text myscore;
void OnCollisionEnter2D(Collision2D target)
{
score += 10;
myscore.text = "Score: " + score.ToString("F");
}
So, when I drag and drop the text UI into the myscore field and then I click on override to save this change in my prefab, it doesn't get saved. I have already tried to change Public to Serialized Private field and even tried to take it as a public text array and even as a private serialized text array element but it didn't worked as well. Please solve this problem of mine or suggest any other way to accomplish this.
If the Text
object you provide is not part of the prefab itself, it's the expected behaviour.
so what's the solution to this? Because I want to add score display in my game so do you have any other way i can add a score display without facing this kind of problem
I don't see what the problem is actually.
If you need this prefab in multiple places, provide the Text for every prefab instance.
You may be able to use a parent prefab with this prefab + your text object you can reuse where you want.
Your answer
Follow this Question
Related Questions
UI components all disappear on Play mode, then stay invisible 2 Answers
Display text above prefabs in Unity 4.6 0 Answers
UI Text.color not assigning? 2 Answers
Trouble instantiating ui text 2 Answers