- Home /
Change scene automatically without collider/trigger
I have a script that changes the scene with a Collider and trigger. I want to change the script so that the scene changes by itself over a certain amount of time. Here is the script I have.
using UnityEngine;
using System.Collections;
public class LoadLevel : MonoBehaviour
{
void OnTriggerEnter(Collider other){
AutoFade.LoadLevel("splashscreen2" ,3,1,Color.black);
}
}
gui loading screen is not needed. This is mostly for some splash screens.
AutoFade refers to another script I have that fades out the scene and then fades in the next one.
It didn't seem to work. I placed it on an empty and changed (name) to ("splashscreen2") and the texture also did not show.
Answer by The_Magical_Kiwi · Aug 10, 2013 at 09:55 PM
using UnityEngine;
using System.Collections;
public class LoadLevel : MonoBehaviour{
public int secondsToWait;
int startTime;
void Start(){
startTime = Time.time;
}
void Update(){
if(Time.time - startTime >= secondsToWait){
AutoFade.LoadLevel("splashscreen2" ,3,1,Color.black);
}
}
}
Not particularly elegant but it should work. Also take a look at http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.StartCoroutine.html as this is probably a better way of doing this.
Your's gave me this error on line 11.
Assets/OfflineTests/Scripts/LoadLevel.cs(11,9): error CS0266: Cannot implicitly convert type float' to int'. An explicit conversion exists (are you missing a cast?)
Your answer