Search Unity

referring to a text field in a 3d text

Discussion in 'Scripting' started by Zefyros, May 22, 2019.

  1. Zefyros

    Zefyros

    Joined:
    May 22, 2019
    Posts:
    3
    I need to add add 1 to a text mesh in a 3D text but I'm unsure how to reference it.
    I'm trying to add 1 to the amount there is on it using a line similiar to this (after an if line):
    text = text + 1;
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    This will not work because when you add number to text. You must have integer variable somewhere. First add 1 to it, then push it to text component as a string.

    Code (CSharp):
    1. public int TotalScore;
    2. public Text ScoreLabel;
    3.  
    4. public void AddPoint(){
    5.   TotalScore = TotalScore + 1;
    6.   ScoreLabel.text = TotalScore.ToString();
    7. }