Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

buildindex does not exist in the current context.

Discussion in 'Scripting' started by craftgaming0811, Oct 18, 2020.

  1. craftgaming0811

    craftgaming0811

    Joined:
    Oct 18, 2020
    Posts:
    5
    I have just started using unity and I have Been using Brackeys tutorial on how to Make a game. I am using the animation system to create an event which will load a new scene using this code.
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.SceneManagement;
    3. public class LevelComplete : MonoBehaviour
    4. {
    5.     public void LoadNextLevel ()
    6.     {
    7.         SceneManager.LoadScene(SceneManager.GetActiveScene(BuildIndex + 1));
    8.  
    9.     }
    10. }
    11.  
    The console says:
    Assets\LevelComplete.cs(7,60): error CS0103: The name 'BuildIndex' does not exist in the current context
    The tutorial is 3 years old so I think unity may have changed build index works.
    Any thoughts?
     
    leventepallo likes this.
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,590
    Go re-check the video. Compare closely to what you wrote. See the difference. Fix it :)
     
    leventepallo and craftgaming0811 like this.
  3. craftgaming0811

    craftgaming0811

    Joined:
    Oct 18, 2020
    Posts:
    5
    Thanks, I just found out I was meant to write it outside of the brackets and now it works.
     
    leventepallo and Yoreki like this.