M
M
Mark Kochetkov2020-12-20 16:40:22
C++ / C#
Mark Kochetkov, 2020-12-20 16:40:22

C# Error Invalid expression term ')' how to fix?

I'm making a game in Unity And I got the error " Invalid expression term ' )' "
Here is the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Money : MonoBehaviour{

  private Text txt;
  private int count;

  void Start (){
    txt = GameObject.Find ("Text").GetComponent <TextMeshPro-(UI)> ();
  }

  void OnTriggerEnter (Collider other){
    count++;
    txt.text = "Ваш счёт: " + count.ToString ();
  }
}


And please explain how this line of code works in detail:
private Text txt;

void Start (){
  txt = GameObject.Find ("Text").GetComponent <TextMeshPro-(UI)> ();
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
VitiaKotik, 2020-12-20
@Mrak00nea00

Remove brackets in TextMeshPro-(UI), replace with TextMeshPro (depending on which component you want to get).
And it is also strange that you are trying to write an object of the TextMeshPro type into a variable of the Text type
How it works: We are
looking for a GameObject with the name Text, we get the TextMeshPro component from it (or whatever you have) and writes it to the txt variable.

G
GavriKos, 2020-12-20
@GavriKos

But it does not work in any way - you have just an error in it, most likely. Because there is no such class TextMeshPro-(UI).
And in order to understand how it works and how to fix such trivial errors, you first need to learn seasharp, and not just units

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question