Please guys if this is a new question i’m sorry this is literally my first time making a game.
TL;DR: Need to make player get out of one side of the camera view and appear in the other side, I’m using OnTriggerEnter2D
but can’t get the Player game object Transform, to alter it’s value.
So I’m making a doodle jump style game, I’ve already came pretty far, I have animations, one way collision platforms. the bounce is just right, and i can spawn a bunch of platforms and make the screen follow the player.
I’m now trying to make the player enter in one side of the screen (camera view) and come out of the other keeping it’s height and velocity. I’ve looked into a lot of tutorials, into forums Youtube tutorials, but i just cannot get how i can do it.
This is currently my code
public class TeleportFunction : MonoBehaviour
{
public Transform LeftWall;
public Transform RightWall;
void OnTriggerEnter2D(Collider2D Player)
{
if (Player.gameObject.tag == "Left")
{
Debug.Log("Left");
}
else if (Player.gameObject.tag == "Right")
{
Debug.Log("Right");
//Transform = RightWall;
}
}
}
In this Debug.Log every time my player hits the box collider I’ve set in the edges of screen it shows the correct side in console. But when i try to use Get.Componet <Transform>
to get the player position and change it to the values of either public Transform LeftWall;
or public Transform RightWall;
It doesn’t work. I’ve tried to just get the this values trough the “Player” on the OnTriggerEnter2D
but with no success either.
If anyone knows this can you help Me ?