Names of the facilities of Unity, C Sharp



  • I have 80 objects and everyone has a name in public string on one violin. All objects that were clicked in another window, those that were not clicked, must be removed. Logic thought it would be. Creating a violin where a leaf or a mass will accept the names of objects and through UI. I'll take them out.

    Reception of names

    [SerializeField] private Text LeftText;
    

    public static string[] NameObj;
    public static List<string> NameObj = new List<string>();

    private void Start()
    {
    for (int i = 0; i < NameObj.Count; i++)
    {
    //LeftText.text += TClickObj.ObjName + "\n ";
    LeftText.text = $"\n" + NameObj[i];
    //LeftText.text = $"{NameObj[i]}\n";
    //Console.WriteLine(NameObj[i]);
    }

    LeftText.fontSize = 30;
    

    }
    //public static void GetName(string Name)
    //{
    //for(int i = 0; i < NameObj.Length; i++)
    //{
    // NameObj.Add(Name);
    //}
    //NameObj.Add(Name);
    //}

    And the violin where the name click is

    public string ObjName;

    public void OnMouseDown()
    {
    if (!one)
    {
    TCore.CC++;
    one = true;
    //TTextControl.GetName(ObjName);
    TTextControl.NameObj.Add(ObjName);

    }
    

    }



  • For those who will ski. On an object that needs to be clicked:

    [SerializeField] private string _ObjName;
    public string Name { get => _ObjName; }
    [SerializeField] private bool _isClicked;
    public bool isClicked { get => _isClicked; }
    

    private void OnMouseDown()
    {
    _isClicked = true;
    }

    Then we create two text fields, add them through the inspector and in the new violin:

    public class Visualizer : MonoBehaviour
    {

    [SerializeField] private Text LeftText;
    [SerializeField] private Text RightText;
    private Naming[] _AllNamingObjects =&gt; FindObjectsOfType&lt;Naming&gt;();
    private List&lt;string&gt; ObjectsText = new List&lt;string&gt;();
    private void Start()
    {
        LeftText.fontSize = 30;
        LeftText.text += $"Найдено:\n ";
        for (int i = 0; i &lt; _AllNamingObjects.Length; i++)
        {
            if (_AllNamingObjects[i].isClicked)
            {
                LeftText.text += _AllNamingObjects[i].Name + $"\n";
            }
    
        }
    
        RightText.fontSize = 30;
        RightText.text += $"Не найдено:\n ";
        for (int i = 0; i &lt; _AllNamingObjects.Length; i++)
        {
            if (!(_AllNamingObjects[i].isClicked))
            {
                RightText.text += _AllNamingObjects[i].Name + $"\n";
            }
        }
    }
    

    }



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2