unity teleport script code example

Example 1: unity 2d teleport script

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

public class Teleportation : MonoBehaviour {

	public GameObject Portal;
	public GameObject Player;


	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		
	}

	public void OnTriggerEnter2D(Collider2D other)
	{
		if (other.gameObject.tag == "Player") 
		{
			StartCoroutine (Teleport ());
		}
	}


	IEnumerator Teleport()
	{
		yield return new WaitForSeconds (0.5f);
		Player.transform.position = new Vector2 (Portal.transform.position.x, Portal.transform.position.y);
	}
}

Example 2: unity teleport script 3D

THE SCRIPT UNDER MINE UNDER MINE IS A FAKE ONE AS YOU CAN SEE IN THE CODE IT SAYS COLLIDER 2D AND ONTRIGGERENTER2D DONT USE THE OTHER SCRIPT

Tags:

Misc Example