Answer the question
In order to leave comments, you need to log in
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 ();
}
}
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
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question