I need a script that when my player walks through a door, it will teleport them to a different scene, is there anywhere to start with this?
You would put a collider on your player GameObject and mark it as a trigger. Then you would put a collider (propably with no visible geometry) behind the door. In your Build Settings you put your second level in the build list. You could then put a script like this on the door collider:
using UnityEngine;
using System.Collections;
public class LoadNewLevelOnContact : MonoBehaviour {
// set as public variable in Editor
// usually 0 for first level
// 1 for target level
public int levelIndexToLoad;
public void OnTriggerEnter ( Collider cTrigger ) {
// the Editor automatically offers the tag "Player" for GameObjects
// if the trigger object is not tagged as Player, ignore it
if ( !cTrigger.tag == "Player" ) { return; }
Application.LoadLevel ( levelIndexToLoad );
}
}
Your question is very basic. Study the tutorial videos on the Unity YouTube channel and take a look at the Asset Store → Unity Essentials → Complete Projects.
Thanks, i owe you one!
Im getting a parsing error. do you need a copy of my script to see whats wrong with it?
You can post the whole script if you want, sure ( in CODE tags please). Then again it’s hard to judge without the context of your project.
However, a parsing error should be visible in your code editor (like MonoDevelop) as a red marking, so you might be able to fix it there. Chose something like “Create CSharp Solution” from the menu (Cmd-K on Mac), then MonoDevelop will point to all kinds of errors.
actually, i fixed it, but thanks anyway