Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

GUIText Variable Mid-Sentence

Discussion in 'Scripting' started by jailbar, Jun 25, 2013.

  1. jailbar

    jailbar

    Joined:
    Nov 21, 2012
    Posts:
    49
    For some reason I can't play a variable in the middle of a GUIText.

    Here's what I would like to do.

    Code (csharp):
    1. GuiText.text = "There are "+variable" ducks in the pond.";
    instead of...

    Code (csharp):
    1. GuiText.text = "You notice some ducks in the pond. Total: "+variable;


    Problem is, it gives me a script error saying that something is out of position.

    Thanks if you can help.
     
  2. Falin

    Falin

    Joined:
    Sep 29, 2009
    Posts:
    242
    For everything you want to add too the string you need a +-sign in-front of it.

    Code (csharp):
    1.  
    2. GuiText.text = "There are "+variable" ducks in the pond.";
    3.  
    should be:

    Code (csharp):
    1.  
    2. GuiText.text = "There are " +variable +" ducks in the pond.";
    3.  
     
unityunity