- Home /
How to write a script which will switch the scene after the character reached a location?
I have a game, which has multiple scene. what i think is, when the character to go to a location, and the scene would change, and the character will spawn in the new scene, how do i write script?
Answer by kabel · Sep 09, 2011 at 11:32 AM
create a boxcollider, scale it and place at the end. check isTrigger in Inspector to true. create a script attach it to the boxcollider.
here is untested code:
using UnityEngine;
using System.Collections;
public class EndOfLevel: MonoBehaviour {
public string Level = "Level 0";
void OnTriggerEnter(Collider other) {
if (other.gameObject.CompareTag("Player"))
Application.LoadLevel(Level);
}
}
Sources:
http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnTriggerEnter.html http://unity3d.com/support/documentation/ScriptReference/GameObject.CompareTag.html http://unity3d.com/support/documentation/ScriptReference/Application.LoadLevel.html
hope it helps!
Your answer
Follow this Question
Related Questions
Having a changing Skybox depending on location of player 1 Answer
The associated script cannot be loaded. 1 Answer
Can a script be loaded to a next scene? 3 Answers
Detecting both eye and location movements on Unity using HTC Vive and collecting the data 0 Answers
how do I create a character 2 Answers