Need scenes to transition on timer and loop back to first scene.

Hey I know how to use Unity but only from an Artists perspective, I’ve done a little bit of scripting but very basic.

Any knowledgeable individuals who could write up a script that simply changes scenes, Scene1 > Scene2 > Scene3 on a timer, IE 20 seconds per scene and loops back to scene 1 endlessly? I’ve searched the forums and I’ve found some stuff on scene transitions but I don’t really know enough about coding to make it do what I want. I feel like it would be simple to do for someone who knows C.

I’m basically trying to showcase character artwork realtime in engine rather than creating a video because it would be a lot higher quality to just run an exe.

This should do what you want.

using UnityEngine;
using System.Collections;

public class SceneSwitcher : MonoBehaviour
{
	void Awake()
	{
		DontDestroyOnLoad(gameObject);
	}
	
	IEnumerator Start()
	{
		int numScenes = (m_scenes == null) ? 0 : m_scenes.Length;
		if (numScenes == 0) yield break;
		
		int sceneIndex = 0;
		while (true)
		{
			Scene scene = m_scenes[sceneIndex];
			Application.LoadLevel(scene.m_name);
			yield return null; // Wait a frame for the new scene to load
			yield return new WaitForSeconds(scene.m_duration);
			
			if (++sceneIndex == numScenes) sceneIndex = 0;
		}
	}
	
	[System.Serializable]
	class Scene
	{
		public string m_name = "";
		public float m_duration = 1.0f;
	}
	
	[SerializeField]
	Scene[] m_scenes;
}

The code will need to go in a C# file called SceneSwitcher.cs.

To use it, create a new empty scene, add a game object to the scene and add this script to the game object. Then fill in the ‘Scenes’ list with your scenes. Save the scene as something like ‘BootScene’. Then in your build settings make the boot scene first in the list so the app starts in that scene.

What you won’t want to do is add the scene switcher to one of your own scenes because each time that scene loads a new copy of the switcher will get created, which could cause some problems.

Edit: It’s worth pointing out that drag and drop won’t work with the ‘Scenes’ list. You’ll need to fill in the scene names by hand. This is unfortunately a Unity limitation.