Scene is loading in Game Mode, but not in the build. Why?
Hello, I'm making a 2D game, where is I think not so many objects to make cause the problems in loading another scene, but in the build, the second level is not loading, except if I try to play the game in Unity program in Game-Mode it works fine and quickly.
What can cause the problems? Any pieces of advice?
It's strange because in game-mode it loads fine, but in the build, it just stops the process without any errors!
P.S. I even tried to delete about all the objects in the scene before it will load another level, and the problem still exists even its loading the scene now, but very slow, but the level looks like just a camera on each other when it's loading.
The main part is in the end.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Scene$$anonymous$$anagement;
public class $$anonymous$$eyCodeTrigger : $$anonymous$$onoBehaviour {
public $$anonymous$$aterial main$$anonymous$$at;
public $$anonymous$$aterial new$$anonymous$$at;
public bool trigger;
public bool is$$anonymous$$atNew;
public float thres;
public float max;
static float t;
public GameObject theObject;
public GameObject text;
public GameObject $$anonymous$$eyCodePanel;
public GameObject deleteObjects;
void Start () {
theObject.GetComponent<Collider2D> ();
is$$anonymous$$atNew = false;
thres = new$$anonymous$$at.GetFloat ("_Threshold");
}
void Update () {
if (is$$anonymous$$atNew == false)
{
theObject.GetComponent<SpriteRenderer> ().material = main$$anonymous$$at;
$$anonymous$$eyCodePanel.gameObject.SetActive (false);
}
if (is$$anonymous$$atNew == true)
{
t = 0.75f * Time.time;
thres = $$anonymous$$athf.PingPong (t, max) + 0.2f;
new$$anonymous$$at.SetFloat ("_Threshold", thres);
theObject.GetComponent<SpriteRenderer> ().material = new$$anonymous$$at;
}
if (is$$anonymous$$atNew == true && Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.E))
{
$$anonymous$$eyCodePanel.gameObject.SetActive (true);
}
if (CodePanel.playerCode == CodePanel.correctCode)
{
Destroy (deleteObjects);
StartCoroutine (WaitSec ());
}
}
void OnTriggerEnter2D(Collider2D theObject)
{
if (theObject.gameObject.tag == "Player")
{
is$$anonymous$$atNew = true;
text.gameObject.SetActive (true);
}
}
void OnTriggerExit2D(Collider2D theObject)
{
is$$anonymous$$atNew = false;
text.gameObject.SetActive (false);
}
IEnumerator WaitSec()
{
yield return new WaitForSeconds (1);
Scene$$anonymous$$anager.LoadScene ("Level-2");
yield return null;
}
}
Answer by MagnaDever · Jun 05, 2018 at 03:50 PM
Try use "LoadSceneAsync"
I'm about to make it, but I'm not sure how.
Because I want to start loading the second level in the middle of the first level by trigger/checkpoint
don't know how correctly I made this if know how to make it please try to help.*
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Scene$$anonymous$$anagement;
public class CheckPointSystem : $$anonymous$$onoBehaviour {
public Level$$anonymous$$anager level$$anonymous$$anager; private BoxCollider2D myCollider; public bool asyncLoaderStart; public bool loaded = false; public bool startLoadNewLevel = false; void Start () { myCollider = GetComponent<BoxCollider2D> (); level$$anonymous$$anager = FindObjectOfType<Level$$anonymous$$anager> (); } void OnTriggerEnter2D(Collider2D col) { if (col.tag == "Player") { myCollider.enabled = false; level$$anonymous$$anager.currentCheckpoint = gameObject; Debug.Log ("Activated Checkpoint " + transform.position); if (asyncLoaderStart == true) { StartCoroutine (AsyncLoad ()); } } } IEnumerator AsyncLoad() { AsyncOperation asyncLoad = Scene$$anonymous$$anager.LoadSceneAsync ("Level-2"); asyncLoad.allowSceneActivation = false; while (!asyncLoad.isDone) { yield return null; } if (asyncLoad.isDone) { loaded = true; } if (startLoadNewLevel == true && loaded == true) { asyncLoad.allowSceneActivation = true; } }
It's normal situation. I need screen of build settings window
Answer by abuelitovip · Jun 05, 2018 at 07:23 PM
Start can you test in unity editor the first scene of build list?
other option is disable the second level of build and test, if the game don´t jump to the next scene, the problem is the first scene on the build list.
Your answer
Follow this Question
Related Questions
LoadScene will only work from first scene 1 Answer
LoadScene not working 0 Answers
How to fix Loading Screen? 0 Answers
Is there any way to recreate the executable? 0 Answers
Hello , I will like a little bit of help regarding a game that I create. 0 Answers