Sunday, April 30, 2017

Teleporting Script (Update)

Directions on how to use:
After creating the script, add it to your FPS controller. Under teleporter, put the object you want to teleport to. It's something you're not going to see so it doesn't really matter what it is-preferably something small for the sake of file size.

For that object (the one being teleported to), you need to turn off the mesh renderer (this will make the object invisible).

Now, you need to deal with that is acting as the thing that teleports the player. Ideally this should be something simple like a painting/picture or something as the like. Partly, this is due to the fact that it doesn't work so well with physical colliders. You do still need to add a collider, but make you click the is trigger box.

Now the other thing you need to do-which enables the whole thing to work in the first place. Up by the name of the object in the Inspector, there is a trait called Tag. You need to create a new tag called teleport and set it to the object. Now this does technically mean you can have multiple objects that teleport, but they will all teleport to the same place. But if you want to do that, then go ahead.

Anyway, that's pretty much it. Here's the script. Just copy and paste it into a new script like with the door animation script.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Teleport : MonoBehaviour{

    public Transform teleporter;

    void Start(){
    }

    void Update(){
    }

    void OnTriggerEnter(Collider other) {
        if (other.gameObject.tag == "teleport") {
            this.transform.position = teleporter.transform.position;
            this.transform.rotation = teleporter.transform.rotation;
        }
    }
}

No comments:

Post a Comment