- Home /
/TestScript.cs(26,21): error CS1525: Unexpected symbol `}'
I just doing a repeat in code of what I just did in the if statement to the else statement. I'm trying to get the scene to switch if the score is not reach . I did do an else statement and I keep get this same error /TestScript.cs(26,21): error CS1525: Unexpected symbol `}' . TestScript.cs(37,1): error CS8025: Parsing error
Here is my code :
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class TestScript : MonoBehaviour
{
public MyClockScript myClock;
public ScoreManagerScript scoremanager;
public int scoreToReach = 99; // change this value to what you want
public int leastscore = 50;
public string nextScene = "FY"; // change this value to what you want
void Update ()
{
if (myClock.m_leftTime <= 0)
{
if ((ScoreManagerScript.score >= scoreToReach) && (nextScene != ""))
{
SceneManager.LoadScene(nextScene);
}
else
{
((ScoreManagerScript.score >= scoreToReach) && (nextScene != ""))
}
}
}
}
Answer by Jessespike · Aug 14, 2016 at 04:37 AM
Change ScoreManagerScript
to scoremanager
in the if-statement and delete the else-statement.
void Update() {
if (myClock.m_leftTime <= 0)
{
if ((scoremanager.score >= scoreToReach) && (nextScene != ""))
{
SceneManager.LoadScene(nextScene);
}
}
}
Nah, this is fine and works. You are missing something. At least say what the error is, I'm thinking you copy-pasted and overwrote a curly brace. Double check for any missing or mismatch with the curly braces "{ }", Specifically the one that encapsulates the class.
Well, changing Score$$anonymous$$anagerScript
to scoremanager
might have been the wrong suggestion as it's purely based on assumptions and most likely wrong since the compiler has gone down to that "wrong" line "25" so Score$$anonymous$$anagerScript.score
has to compile just fine. "score" is most likely a static variable so he has to use Score$$anonymous$$anagerScript.score
.
That's a good point, score could be static and probably is. In that case OP, use Score$$anonymous$$anagerScript.score
ins$$anonymous$$d.
I have already seen Score$$anonymous$$anagerScript.cs and the score property is static so this is not a problem. It is inside the else block where you have this
((Score$$anonymous$$anagerScript.score >= scoreToReach) && (nextScene != ""))
that is your problem. Just commenting out the line or deleting the whole else block like @Jessespike mentioned will get rid of the error.