Make a script that teleports the player between two scenes.

I have UFPS and I am familiar with how to create new weapons and items. I want to have a weapon that is a watch (I have the models) and when you click it plays an animation and then after x amount of time it takes you to a scene.

I have:

Scene 1: The City
Scene 2: The Island

When you are in Scene 1 the teleporter will act like so:
Get out teleporter item
Click
Animation plays of some energy beams or whatever
After x amount of time you are teleported to Scene 2.

When you are in Scene 2 the teleporter teleports you to Scene 1
When you are in Scene 1 the teleporter teleports you to Scene 2

Here’s a completely noobish outline:

If (“the player is in Scene 1”)
Then (“play animation, wait x amount of time then take player to scene 2”)
Else (“play animation, wait x amount of time then take player to scene 1”)

This would work because if the computer detects the player in a scene 3 or higher, it would move the player to scene 1, which would act as the hub anyways.

You can try something like this:

using UnityEngine;
using System.Collections;

public class TeleportScript : MonoBehaviour {

   //this is a reference to the Animator that contains the Animation you want to play
    public Animator anim; 

    void Start()
    {
       //this line is so that this object persists through each scene. 
       //you would put this script on the watch or any teleport device
        DontDestroyOnLoad (this); 
    }
   
    void Update () {
        if (Input.GetKeyDown(KeyCode.X))    //I arbitrarily chose to make all the magic happen when I press x
        {
 
            if (Application.loadedLevel == 1) //checks if the current level is 1. this level would have to be the second item in your build settings, since the list starts at 0, so 1 is technically the second scene.
            {
                StartCoroutine(Teleport(1)); //starts the teleport coroutine and passes in a value of 1 for the level. coroutines can be used for waiting x seconds. 
            }

            if (Application.loadedLevel == 2)  //checks if the current level is 2
            {
                StartCoroutine(Teleport(2)); //passes in 2

            }

            if (Application.loadedLevel > 2) //checks if the current level is anything other than 1 or 2
            {
                StartCoroutine(Teleport(1)); //passes in 1, since it's the hub
            }

        }
    }

    IEnumerator Teleport (int i)
    {
        anim.Play ("NameOfAnimation"); // first thing that happens is the animation plays. Replace NameOfAnimation with the string name of the clip you want to play.

        yield return new WaitForSeconds (3); //there is a 3 second pause
       

       //then depending on what i is, the value that got passed in, (where i is equal to the current level)
      // it loads the level to be teleported to
        if (i == 0)
            Application.LoadLevel (1);
        else if (i == 1)
            Application.LoadLevel (0);
        else {
            Application.LoadLevel (0);
        }

    }


}