Wednesday, April 19, 2017

Teleporting Script

Below is the script to make your controller teleport. How to use: put the script on your FPS controlled. Set Teleporter to wherever you want to teleport to. Now on whatever you want to be the teleport trigger, on the top of the inspector under its name, there is a Tag. Make a new tag called teleport and select it. It should then work. This means that you can have multiple things that act as teleporting trigger but they'll all end up in the same place. Script is below.

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