teleport to and fro between surfaces at different heights
i have surfaces at different heights (32 meters between each other) like inside a building.
I want teleport the player between different floors of the building to and fro.
i am new to unity and i created teleport pads and target plane along with its C# script from one floor to the next as below but in order to make the player go to the next floor do i have to create another teleport pad and target and another C# script
also if i want to go back to the previous floor, do i have to create a separate script for that too?
does it have to be a tedious process of so many scripts or just one script can be amended?
Answer by magicdog2013gamez · Jun 10, 2020 at 04:50 AM
It doesn't know what the destination is Try something like this
public enum TriggerType {Enter, Exit};
[Tooltip ("The Transform to teleport to")]
[SerializeField] Transform teleportTo;
[Tooltip ("The filter Tag")]
[SerializeField] string tag = "Player";
[Tooltip ("Trigger Event to Teleport")]
[SerializeField] TriggerType type;
void OnTriggerEnter (Collider other)
{
if (type != TriggerType.Enter)
return;
if (tag == string.Empty || other.CompareTag(tag))
other.transform.position = teleportTo.position;
}
void OnTriggerExit (Collider other)
{
if (type != TriggerType.Exit)
return;
if (tag == string.Empty || other.CompareTag(tag))
other.transform.position = teleportTo.position;
}
}
The exit is the destination and the enter is the start, Tell me if it doesn't work I just quickly attempted to convert it from 2d to 3d
Thanks for your help. i will try your method once i am more acquainted with scripting.
while waiting for any reply, i actually could create multiple teleport pads and targets by using copy paste command and only changing their teleport(script) references. there was no need to create multiple scripts which i had feared.
attached is a screenshot below and it worked really fast to setup for moving between floors.