Unity Text.text is not changing text in function

Whenever I try and use Text.text to change the text for the UI it doesn’t work. The text doesn’t change. The weird thing is it does change in my Start function… Here is the code for the function that doesn’t change:

public void BuyItems ()
	{
		print ("Changing text?");
		GoldText.text = "2";
	}

EDIT:

Full script: using UnityEngine;using UnityStandardAssets.CrossPlatformInput;using UnityEn - Pastebin.com

I also realized that after I stop the game and start it again the text is 2 which is what I was trying to change it to in the first place. Then if I start it again it goes back to what the Start method is changing it too. It seems that the text only gets updated after I stop the game and start it again…

If it is updating in your Start method, that means Ui Text is properly assigned to your ‘GoldItems’. This indicates your later function ‘Buyitems’ is not being called properly or the value of text is being updating some where else.

One of the possible things can be there :.

  1. Either your BuyItems() function is not calling from your scripts. You don’t have called it from onClick event of button or from some other methods.

  2. May be your BuyItems() function is calling but as it set text to “2” after that some other methods should have change GoldText to something else.

If you are not able fix after checking above 2 things then you have to show script.