Search Unity

Question Why string from TextMeshProUGUI is not parsed into a number ?

Discussion in 'UGUI & TextMesh Pro' started by Ander_kot, Feb 23, 2023.

  1. Ander_kot

    Ander_kot

    Joined:
    Dec 21, 2020
    Posts:
    2
    I have no idea why it doesn't work
    upload_2023-2-24_0-54-2.png

    but it works
    upload_2023-2-24_0-57-6.png

    7 is 7, which is obtained from TextMeshProUGUI, which is written in code.

    So why is the first 7 not a number, but the second 7 is a number?
     
  2. Ander_kot

    Ander_kot

    Joined:
    Dec 21, 2020
    Posts:
    2
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Text.RegularExpressions;
    using TMPro;
    using UnityEngine;

    public class EffectMng : MonoBehaviour
    {
    public Shader shader;
    public SpriteRenderer Effect;
    public GameObject OnButton;
    public GameObject OffButton;
    public TextMeshProUGUI TextMesh;
    public string CurrValue = "1";

    void FixedUpdate()
    {
    float CF;
    //string newCurrValue = TextMesh.GetParsedText();
    //Regex.Replace(newCurrValue, @"\W+", "", RegexOptions.IgnoreCase);
    string newCurrValue = "7";

    if ((CurrValue != newCurrValue) & (Single.TryParse(newCurrValue, out CF)))
    {
    CurrValue = newCurrValue;
    if (CF < 1f)
    CF = 1f;
    //Effect.material = new Material(shader);
    Effect.material.SetFloat("_Radius", CF);
    }

    }
    }