Async Scene Load for Gear VR
Hi all, I am relatively new to Unity and one of my scenes in the gearvr consistently loads very slowly.
I have modified the script to have the next scene load asynchronously but now instead of waiting for the scene change parameters I have set up (either clicking on a mesh renderer or 30 seconds into the scene) the new scene transitions as soon as its finished loading even though I set "allowSceneActivation" to false unless one of those two aforementioned conditions are met.
Below is the script. Any thoughts/ideas about how I can correct this (load the new scene asycnhonously but still keep the scene transition triggers I have created) I would be greatly appreciated!
Thank you!
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;
public class CameraRaycast_Earth: MonoBehaviour {
public MeshRenderer rend;
public bool hovering;
public bool hoveringOld;
private float intervalMax = 30.0f;
private float currentTimerValue = 30.0f;
AsyncOperation asyncLoad;
void Start() {
asyncLoad = SceneManager.LoadSceneAsync("BK_LightsOffRoadSign");
asyncLoad.allowSceneActivation = false;
}
// Update is called once per frame
void Update() {
Ray ray;
RaycastHit hit;
ray = new Ray(this.transform.position, this.transform.rotation * Vector3.forward);
if (Physics.Raycast(ray, out hit) && hit.transform.tag == "Clickable")
{
hovering = true;
if (Input.GetMouseButtonDown(0))
SceneManager.LoadScene("BK_LightsOffRoadSign");
asyncLoad.allowSceneActivation = true;
}
else{
hovering = false;
}
if (hovering != hoveringOld) {
if (hovering == true){
rend.material.color = new Color(1f, 1f, 1f, .6f);
}
if (!hovering){
rend.material.color = Color.clear;
}
}
hoveringOld = hovering;
if (currentTimerValue >= 0.0f)
{currentTimerValue = currentTimerValue - Time.deltaTime;
}
else if (currentTimerValue < 0.0f){
SceneManager.LoadScene("BK_LightsOffRoadSign");
asyncLoad.allowSceneActivation = true;
}
}
Your answer
Follow this Question
Related Questions
LoadSceneAsync and StartCoroutine still blocks main thread 1 Answer
Async Level loading issue. 0 Answers
Load level async 0 Answers
Load level async 1 Answer
How do I preload multiple scenes? 0 Answers