I'm building a bowling game in which I am trying to save the number of pins fallen on every turn to a UI text box, taken as an array (public Text[] Count
). I'm able to get the first score in the text box, but unable to save it while switching to other scenes.
There are two scenes; one has the ball, pins and alley, and the other scene has the score card, which is displayed in additive mode. The UI text is a child of the canvas. I've used DontDestroyOnLoad
for the canvas, but it doesn't work at all.
I'm actually trying to reuse these values to display the score in the series.
Below is the code
public GameObject rootCanvas;
public Text[] Count;
public static int counter=0;
public static int i;
public static int co = 0;
MovingBall ball = new MovingBall();
public void Start()
{
ball.countText = GameObject.FindWithTag("Counttext").GetComponent<Text>();
for (i=co;i<=29;i++)
{
if (counter < 1)
{
Count[i].text = ball.countText.text;
}
else if (counter == 1)
{
Count[i].text = ball.countText.text;
Count[i+1].text = (Convert.ToInt16(Count[i-1].text) + Convert.ToInt16(Count[i].text)).ToString();
}
counter++;
co++;
DontDestroyOnLoad(gameObject.transform);
return;
}
}
void Awake()
{
rootCanvas = GetComponent<GameObject>();
}
GameObject
never destroy. I think you are findingCanvas
in script and you are getting firstCanvas
which may be theCanvas
of second scene in which is not your desiredCanvas
. Can you show some of your code so we can analyze it? \$\endgroup\$rootCanvas = GetComponent<GameObject>();
? \$\endgroup\$