Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

SceneManagment by BuildIndex

using UnityEngine;
using UnityEngine.SceneManagement;

// Show the buildIndex for the current script.
//
// The Build Settings window shows 5 added Scenes.  These have buildIndex values from
// 0 to 4. Each Scene has a version of this script applied.
//
// In the Project, create 5 Scenes called scene1, scene2, scene3, scene4 and scene5.
// In each Scene add an empty GameObject and attach this script to it.
//
// Each Scene randomly switches to a different Scene when the button is clicked.

public class ExampleScript : MonoBehaviour
{
    Scene scene;

    void Start()
    {
        scene = SceneManager.GetActiveScene();
        Debug.Log("Active Scene name is: " + scene.name + "
Active Scene index: " + scene.buildIndex);
    }

    void OnGUI()
    {
        GUI.skin.button.fontSize = 20;

        if (GUI.Button(new Rect(10, 80, 180, 60), " Loading " + scene.buildIndex))
        {
            int nextSceneIndex = Random.Range(0, 4);
            SceneManager.LoadScene(nextSceneIndex, LoadSceneMode.Single);
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: how to make font factory text to bold in c# 
Csharp :: print bitmap company logo c sharp 
Csharp :: c# Class instance 
Csharp :: how to make enemy killed by bullet unity2D 
Csharp :: blazor editform empty 
Csharp :: c# Least prime factor of numbers till n 
Csharp :: transform.lookat 2d 
Csharp :: how to make a beep in c# 
Csharp :: real world example of sinleton design pattern 
Csharp :: how to if button pressed do something in c# 
Csharp :: executesqlinterpolatedasync stored procedure 
Csharp :: how do you search for how many times a character appears in user input on c sharp 
Csharp :: copy file image in c# 
Csharp :: drop column with code first asp.net core 
Csharp :: c# aabb box rotate 
Csharp :: firefoxoptions setpreference to trust certificates 
Csharp :: How to add a button to a column in the DataGridView 
Csharp :: chrome devtools capture all styling an element uses 
Csharp :: how to use a round image unity 
Csharp :: print all string in textbox in array c# 
Csharp :: c# expandoobject indexer 
Csharp :: c# task call more web api in parallel 
Csharp :: lambda distinct by property 
Csharp :: unity 2d top down movement script 
Csharp :: c# parsing datetime from string irrespctive of culture 
Csharp :: how to refrence a variable from other script in c# 
Csharp :: We create a PdfDocument, not a (MigraDoc) Document 
Csharp :: Auto select file in Solution Explorer from its open tab 
Csharp :: count split elements .net 
Csharp :: anidate bucle in c# 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =