- Home /
Teleporter
Hi I've been working on this project in my spare time and have ran into a little issue which I need some help with,
https://i.gyazo.com/b4411a00d9df6ba038d7f2844466f12f.png![alt text][1]
Basically I'm trying to get player to teleport from object 1 > 2 (white things)
I have box collider set on object one and have tried to set trigger on it with no luck, I've tried to use the script on player and teleporting object, :) if some could help it would mean alot!
I've gone through alot of tut on this site and youtube but had no luck! :)
Here my script using UnityEngine; using System.Collections;
public class Teleport: MonoBehaviour
{
public GameObject Power_template;
public GameObject Power_template2;
void OnTriggerEnter(Collider other)
{
// What I am doing is checking for the name of what you are colliding with to determine where the player teleports to.
// This can also be done by checking it's tag instead of it's name if preferred.
switch (other.name)
{
case "Power_template":
gameObject.transform.position = Power_template.transform.position;
break;
case "Power_template2":
gameObject.transform.position = Power_template2.transform.position;
break;
}
}
}
[1]: https://i.gyazo.com/b4411a00d9df6ba038d7f2844466f12f.png
Answer by Unitykullanici · Dec 09, 2017 at 05:37 PM
Edit 16 as " gameObject.transform.position = Power_template.transform.position + new Vector3(-1, 0 ,0);" And 12 as " gameObject.transform.position = Power_template2.transform.position - new Vector3(0, -1 ,0);"
Do you mean like this? using System.Collections; using System.Collections.Generic; using UnityEngine;
public class teleport : $$anonymous$$onoBehaviour
{
public GameObject Power_template;
public GameObject Power_template2;
void OnTriggerEnter(Collider other)
{
// What I am doing is checking for the name of what you are colliding with to deter$$anonymous$$e where the player teleports to.
// This can also be done by checking it's tag ins$$anonymous$$d of it's name if preferred.
switch (other.name)
{
case "Power_template":
gameObject.transform.position = Power_template2.transform.position - new Vector3(0, -1, 0);
break;
case "Power_template2":
gameObject.transform.position = Power_template.transform.position + new Vector3(-1, 0, 0);
break;
}
}
}
@ClintonBates Yes if you teleport inside a rock change new Vector3(0, 1, 0) to new Vector3(1, 0, 0) or new Vector3(1, 0, 0) to new Vector3(0, 1, 0).
Still no luck sadly. :( thanks for trying :)
I remember it: https://youtu.be/xQEfktXtfL$$anonymous$$ It's a tutorial for make portal very easy but it is in Turkish language I don't know can you understand. But codes are always same
Your answer
![](https://koobas.hobune.stream/wayback/20220612144253im_/https://answers.unity.com/themes/thub/images/avi.jpg)