So I’m basically trying to get my character to “use” a set of stairs by teleporting from one stairway door to another. Each stairway door will be paired with one other stairway door.
Here’s the code, I feel like it should be working…my Debug.Logs are even outputting the correct information. Also FYI, I have the Transform doorPairedWith as public so that I can just drag and drop the stairway door that each one is supposed to be paired with.
using UnityEngine;
public class Stairs : MonoBehaviour {
Player player;
public Transform doorPairedWith;
Vector3 doorPairedWithPosition;
Vector3 playerPosition;
BoxCollider2D playerCollider;
BoxCollider2D stairsTriggerCollider;
bool playerIsNearStairs = false;
void Start()
{
player = Player.instance;
playerPosition = player.transform.position;
doorPairedWithPosition = doorPairedWith.position;
playerCollider = player.GetComponent<BoxCollider2D>();
stairsTriggerCollider = GetComponent<BoxCollider2D>();
}
void Update()
{
UseStairs();
}
void UseStairs()
{
if (playerIsNearStairs == true)
{
if (Input.GetKeyDown(KeyCode.E))
{
Debug.Log("Attempting to use stairway door named: " + doorPairedWith);
playerPosition = doorPairedWithPosition;
}
}
}
void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag == "Player")
{
playerIsNearStairs = true;
Debug.Log("Player is near stairs: " + playerIsNearStairs);
}
}
void OnTriggerExit2D(Collider2D collision)
{
if (collision.gameObject.tag == "Player")
{
playerIsNearStairs = false;
Debug.Log("Player is near stairs: " + playerIsNearStairs);
}
}
}