Search Unity

sum values and forward to the text

Discussion in 'Scripting' started by michellynitecki, Apr 26, 2021.

  1. michellynitecki

    michellynitecki

    Joined:
    Apr 26, 2019
    Posts:
    43
    I'm trying to add the values that are inside the [valuetext] with the next one of its element, but it returns the value inserted there and not the sum.


    what do I do ps. [valuetext] is float

    Code (CSharp):
    1.         switch (Index)
    2.         {
    3.             case 0:
    4.             {
    5.                 __text.text = valuetext[0].ToString();
    6.             }
    7.  
    8.             break;
    9.  
    10.             case 1:
    11.             {
    12.                 text.text += valuetext[1].ToString();
    13.             }
    14.  
    15.             break;
    16.             case 2:
    17.             {
    18.                 _text.text += valuetext[2].ToString();
    19.             }
    20.  
    21.             break;
    22.             case 3:
    23.             {
    24.                 {
    25.                     _text.text += valuetext[3].ToString();
    26.              
    27.                 }
    28.             }
    29.  
    30.             break;
    31.         }
    32.     }
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,925
    Just to get an idea here, are you trying to concatenate strings, or add floats (numbers) together?
     
  3. michellynitecki

    michellynitecki

    Joined:
    Apr 26, 2019
    Posts:
    43
    in the post above it does just that about passing float (numbers), the problem is to sum each value to the next in the list and pass it to the text