About 'Update Text Component'!

You’re more than welcome Dave :slight_smile:

Great that you have moved forward and made progress with it, sleep is over-rated, coffee though, absolutely! :coffee: :slight_smile:

1 Like

Hi Chirs, So brackets does help in any way? I am not able to find anything about it.

Hi Manzeet,

In the case of strings it is unnecessary. Obviously with maths you may want to include them to ensure an order of priority, but for strings, no need.

private void Start()
{
    string brackets = ("Some text");
    string noBrackets = "Some text";

    Debug.Log(brackets);
    Debug.Log(noBrackets);
}

The output is the same, it’s also considerably easier to read when looking at your code but two significant benefits of not using the brackets are;

  • reducing the risk of repetitive strain injury
  • not wearing out the paint on the ( and ) keys on your keyboard

:slight_smile:

Note: You are unlikely to see the brackets used in other coding examples online such as Microsoft or Unity documentation

1 Like

Thanks for the quick response. I can sleep peacefully now.

1 Like

hehe, you’re very welcome - sweet dreams! :sleeping: :zzz:

1 Like

Hello Rick. I have a informative question.
I was checking unity documents and saw this.
m_MyText.text = "Text has changed.";
On the udemy class you sugested like this;
textComponent.text = ("I am added programmaticlly! ");
with the brackes.
i would like to ask you whats the diference on using brackets or not using them or they are just two diferent ways of writing the same.
https://docs.unity3d.com/ScriptReference/UI.Text-text.html

Hi @gabrielforgames, the parentheses are unnecessary in this case, they are just a habit that I personally have which stems from requiring them for debug.log statements and for any situation where we join multiple chunks of information together (“this” + “this”). They still work, but are not needed.

Privacy & Terms