- Home /
Error with InvokeRepeating
NOOB ALERT
I'm new to Unity so I'm thinking that I messed up on something really simple.
I'm making a timer-based score system, and I'm using InvokeRepeating
. This is my code:
InvokeRepeating("SecondScore", 0, 1f);
void UpdateScore ()
{
scoreText.text = "Score: " + score * 10;
}
void SecondScore ()
{
score + 10;
}
UpdateScore ()
is when the player destroys something, and SecondScore ()
is the timer.
Now, I'm getting this error that says Assets/_Completed-Assets/Scripts/Done_GameController.cs(84,3): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
. I assume that means that the +
operator is invalid, but that doesn't make sense.
So, what's wrong, and how can I fix it?
Answer by AR_Rizvi · Feb 06, 2017 at 05:00 AM
InvokeRepeating("SecondScore", 0, 1f);
void UpdateScore ()
{
scoreText.text = "Score: " + score * 10;
}
void SecondScore ()
{
score += 10;
}
Score + 10 was the problem compiler dose not seems to understand that what you were trying to do with score as the error said only Only assignment, call, increment, decrements, await, and new object expressions can be used as a statement you have to assign score to something that how it works
Your answer
Follow this Question
Related Questions
Overwritting score with GUI 1 Answer
C#: Q about creating Score system using GUItext 1 Answer
Trying to make simple trigger score counter, having troubles. 0 Answers
Displaying a Score in a Game Over Scene, taken from the MainGame Scene? 0 Answers
NullReferenceException thrown when trying to access a function from another GameObject 2 Answers