- Home /
How to load a random level when button is touched?
Okay, I have seen many answers for this question, but none seem to work. I need a way to randomly select a level between two levels, when a button is touched. I am not very good at making scripts. And iv'e tried many scripts, but none work at all. Does anyone know anything about this?
Answer by aWolfKing · Jun 02, 2016 at 04:30 PM
You can load scenes by their number or name.
int[] numbers = {0,1}; //possible random numbers
string[] scenenames = {"scene1", scene2}; //scene names in order of numbers //0 = scene1, 1 = scene2
SceneManager.LoadScene( scenenames[Random.Range(0,numbers.lenght)] ); //place this inside void
Thanks for answering : ) Though for some reason when I use this script it gives me this error: Assets/RandomLevelHe2.cs(15,17): error CS0103: The name `Scene$$anonymous$$anager' does not exist in the current context.
How about making research in the manual ??
Just import the UnityEngine.Scene$$anonymous$$anagement namespace
Sorry, very new to this. Very, very new!
Answer by BlastOffProductions · Jun 03, 2016 at 12:31 PM
Here is the current script I have: using UnityEngine; using System.Collections;
public class RandomLevelHe2 : MonoBehaviour { public Object He2; public Object TapTest;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {if ((Input.touchCount == 1) &&
(Input.GetTouch(1).phase == TouchPhase.Began) ){
Application.LoadLevel ("He2");
Application.LoadLevel ("TapTest");
}
}
}
(Input.GetTouch(1).phase == TouchPhase.Began) ){
if( Random.value > 0.5f )
Application.LoadLevel ("He2");
else
Application.LoadLevel ("TapTest");
}
Your answer
Follow this Question
Related Questions
How can I swipe function that lets the player select buttons? 0 Answers
Help with touch input for iOS please! 1 Answer
Is touch began guaranteed? 0 Answers
Multi touch not working - What's wrong with this code? 1 Answer
Raycast issue ... 1 Answer