Not able to make new line in Visual studio 2017 using Windows

Hi, Ive been trying to follow along with the video, yet I am not able to execute new line mechanics cause it just doesnt seem to work. I tried /r/n, /n, Environment.NewLine, System.Environment.NewLine and Console Writeline and none of it works. The text color is just white like it doesnt have any function at all. How do I make it work? :frowning:

Can you post your code please?


See also;

Of coure, not sure if i’ve posted it correctly. it’s basically copy paste of the one presented in the video, and according to it there needs to be new line before “press S yada yada”. Here’s example with \n usage. Thanks!

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

public class TextControl : MonoBehaviour {

    public Text text;

	// Use this for initialization
	void Start () {
        text.text = "Hello dude";
		
	}

    // Update is called once per frame
    void Update() {
        if (Input.GetKeyDown(KeyCode.Space))
            text.text = "Lorem Ipsum jest tekstem stosowanym jako przykładowy " +
                        "wypełniacz w przemyśle poligraficznym. Został po raz " +
                        " pierwszy użyty w XV w. przez nieznanego drukarza do. \n\n" +
                         "Press S to view Sheet, M to view Mirror, L to view Lock.";
        }


}

Hi,

You missed the code formatting characters before and after (see link above), I’ve put them in for you for now.

Regarding the \n\n issue, can you also pop a screenshot up of this text being output to the screen please, with the UI Text GameObject selected in the Scene view.

Perfect, but, with the game running.

So;

  • click the Play button at the top, the focus will shift to the Game view
  • press Space to make your text appear
  • click back on to the Scene view
  • select the UI Text GameObject, it should have some text in it now
  • take screenshot

:slight_smile:

Stupid me.

It’s not a problem, I didn’t specify that in the first reply.

Ok, now stop the game from running and resize that UI Text GameObject so that it is taller, and/or wider.

Re-run the steps above.

There is no new line even though the /n/n is “interpreted” cause its not present on the screen. I dont get it :stuck_out_tongue:

It should be \n\n not /n/n, which do you have in you code?

\n\n.I just got it wrong in the message :smiley:

Just to be certain, you don’t have any text set in the actual text field within the Inspector, when the game isn’t running do you?

Zero. Text is set only in the actual code.Line

Hmm, bit odd. I’ve checked the completed project in Unity 2018 and it does as it should.

Could you zip up your project files for me and I will take a look. The forum will allow uploads of up to 10mb, if the project files are larger than that then please use a service like Dropbox / Google Drive and provide me with the URL.

The only one difference I can see is that I don’t have the space before the \n\n but I wouldn’t image that would make a difference, e.g.

"... drukarza do.\n\n" +

wow… who would’ve thought. I deleted the space and it works. But I am dead sure I tried it like 20 times.

That’s even more odd, as I inserted a space and it still worked for me!

1 Like

Ive just added space again and it works as well… ok that’s weird. guess i needed to restart unity or something

1 Like

That’s more likely to be the issue.

Glad you can move forward again anyway… lets blame this one on the Gremlins :slight_smile:

image

Wasted almost 3 hours but didn’t think about restarting, got me real mad. Damn gremlins. Thanks a lot! :smiley:

1 Like

You’re very welcome.

I guarantee though that those 3 hours weren’t wasted… restarting Unity will probably be the first thing you try if you run into problems in the future :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms