Hi, in my game I want to make it so that the playerprefs "leveltoload" will go up a level each time they collide with the objective in different scenes but I'm getting an error. Error: Assets/Scripts/LevelUp.cs(18,100): error CS1525: Unexpected symbol `;', expecting `)', or `,' Code (CSharp): using UnityEngine; using System.Collections; public class LevelUp : MonoBehaviour { public GameObject player; public GameObject objective; void Start() { } void OnTriggerEnter (Collider other) { if(other.gameObject.tag == "Player") { PlayerPrefs.SetInt ("levelToload", (PlayerPrefs.GetInt ("levelToload") + 1); Application.LoadLevel ("NextLvl"); } } }
It's a compiler error that is explaining that you have an extra opening parenthases in your line 18. All parenthases must come in matched pairs. Errors like this are why I prefer to keep every line short. Nesting statements can quickly get confusing. I would suggest rewriting the inner block to this: Code (csharp): const string levelLoadKeyName = "levelToload"; int levelToLoad = PlayerPrefs.GetInt(levelLoadKeyName); levelToLoad += 1; PlayerPrefs.SetInt(levelLoadKeyName, levelToLoad); This is more verbose, but it is also very clear and easy to read. Making code clear and easy to read is a fundamental part of Clean Clode.
Thanks so much! Turns out all I had to do to get it working was add that extra parenthesis at the end of line 18.
Also would anyone know about when the scenes in my game change the lighting goes really dark and loses most of it's color. Can anyone help me fix this please?
There's directional lights in all of the scenes. It doesn't happen if I just play the scene by itself but say if I go to main menu and click play then the play scene will be dark whereas if I just went into the play scene and clicked play it would appear normal.