Day #010

#DAY010

Teleporting to a different location in the scene

Main points covered

#onTriggerEnter

#Collider

 

C# script (attached to the player)

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

public class Teleport : MonoBehaviour {

public GameObject portalview1;
public GameObject portalview2;

void OnTriggerEnter (Collider other){

if (other.name == “portal1”){
this.transform.position = portalview1.transform.position;
}
if (other.name == “portal2”){
this.transform.position = portalview2.transform.position;
}
}
}

 

 

***OBS: collider needs to have the “Is Trigger” checked.

Leave a Reply

Your email address will not be published. Required fields are marked *