- Home /
Question by
Cryno1000 · Mar 20, 2020 at 09:01 PM ·
scene-loadingif-statementsintloading screen
How to see if an int ends with a certain number
So I'm trying to load a scene depending on the end of an int. For example, if depth is equal to something that isn't a multiple of 5 or 10, load one of the 5 different scenes. But if it ends in 5, load the shop and if it's a multiple of 10 [e.g. 20 or 30] load the boss fight scene.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class depthscript : MonoBehaviour
{
public int depth;
public int enemiesremaining;
public Animator camAnim;
public int stagetoload;
public void IncreaseDepth()
{
camAnim.SetTrigger("finishstage");
//if (depth ends in something other than 10 or 5){
stagetoload = Random.Range(1, 5);
if (stagetoload == 1)
{
//load normal
}
if (stagetoload == 2)
{
//load dark
}
if (stagetoload == 3)
{
//load swamp/jungle
}
if (stagetoload == 4)
{
//load ice
}
if (stagetoload == 5)
{
//load fire
}
//}
//if (depth ends in 5 [e.g. 15 or 25]){
//SceneManager.LoadScene("shop");
//}
//if (depth emds in 0 [e.g. 10 or 20 or 30]{
//SceneManager.LoadScene("bossfight");
//}
}
}
Comment
Answer by BBIT-SOLUTIONS · Mar 20, 2020 at 09:06 PM
Seems to be a perfect use case for the modulo operator % ;-)
Your answer
![](https://koobas.hobune.stream/wayback/20220612225401im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to select scene based on device screen size? 1 Answer
How to async load new Scene and Resources simultaneously? 3 Answers
Generating a random number and detecting what number it is 4 Answers
NullReferenceException: Object reference not set to an instance of an object 2 Answers
How can I make a loading screen with LoadSceneAsync 2 Answers