Vydělávej až 160.000 Kč měsíčně! Akreditované rekvalifikační kurzy s garancí práce od 0 Kč. Více informací.
Hledáme nové posily do ITnetwork týmu. Podívej se na volné pozice a přidej se do nejagilnější firmy na trhu - Více informací.
Avatar
Erik Bystroň:11.4.2017 16:33

Ahoj, mám problém s načítáním scény na pozadí, mám scénu se skriptem, který spustí načítání hlavní scený při zmáčknutí mezerníku. Ovšem funguje to jen pokud mam hlavní scénu v build settings jako první (číslo 0). Když je druhá nefunguje to, scena se nenáčítá... Pokud dám hlavní scénu jako první nemá ani načítaní nějaký smysl... Skript není můj našel jsem ho na internetu a upravil jen jednu metodu za novější...

Skript na načítání:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class SceneLoader : MonoBehaviour {

    private bool loadScene = false;

    [SerializeField]
    private int Main;
    [SerializeField]
    private Text loadingText;


    void FixedUpdate() {

        // If the player has pressed the space bar and a new scene is not loading yet...
        if (Input.GetKeyUp(KeyCode.Space) && loadScene == false) {

            // ...set the loadScene boolean to true to prevent loading a new scene more than once...
            loadScene = true;

            // ...change the instruction text to read "Loading..."
            loadingText.text = "Loading...";

            // ...and start a coroutine that will load the desired scene.
            StartCoroutine(LoadNewScene());

        }

        // If the new scene has started loading...
        if (loadScene == true) {

            // ...then pulse the transparency of the loading text to let the player know that the computer is still working.
            loadingText.color = new Color(loadingText.color.r, loadingText.color.g, loadingText.color.b, Mathf.PingPong(Time.time, 1));

        }

    }


    // The coroutine runs on its own at the same time as Update() and takes an integer indicating which scene to load.
    IEnumerator LoadNewScene() {

        // This line waits for 3 seconds before executing the next line in the coroutine.
        // This line is only necessary for this demo. The scenes are so simple that they load too fast to read the "Loading..." text.
        yield return new WaitForSeconds(3);

        // Start an asynchronous operation to load the scene that was passed to the LoadNewScene coroutine.
        AsyncOperation async = SceneManager.LoadSceneAsync(Main);

        // While the asynchronous operation to load the new scene is not yet complete, continue waiting until it's done.
        while (!async.isDone) {
            yield return null;
        }

    }

}

Za jakoukoliv pomoc budu rád, předem díky

 
Odpovědět
11.4.2017 16:33
Avatar
Erik Bystroň:11.4.2017 18:10

Problem nalezen, nechápu jak to, že jsem si toho nevšiml :-D Proměna Main je od začátku nula proto to nešlo |-)

 
Nahoru Odpovědět
11.4.2017 18:10
Děláme co je v našich silách, aby byly zdejší diskuze co nejkvalitnější. Proto do nich také mohou přispívat pouze registrovaní členové. Pro zapojení do diskuze se přihlas. Pokud ještě nemáš účet, zaregistruj se, je to zdarma.

Zobrazeno 2 zpráv z 2.