Hi, Im trying to make a “Portal”- like 2D game and I have started making the portal scripts (it is very barebones right now) and In when I walked thru one of the portals it kept teleporting me back and forth between the two portals due to collision. So I decided to turn off the colliders of the player when entering one of the portals and trying to re-enable the colliders when exiting the portal triggers. It does disable the player colliders when entering the portal but it refuses to enable them again afterwards and I have no idea why!
using UnityEngine;
using System.Collections;
public class PortalScript : MonoBehaviour {
public GameObject otherportal;
public GameObject player;
private Collider2D otherportalCollider;
void Awake(){
otherportalCollider = otherportal.GetComponent<BoxCollider2D>();
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter2D(Collider2D other) {
if(other.tag == "Player"){
other.GetComponent<BoxCollider2D>().enabled = false;
other.GetComponent<CircleCollider2D>().enabled = false;
other.transform.position = otherportal.transform.position;
}
}
void OnTriggerExit2D(Collider2D other){
if(other.tag == "Player"){
other.GetComponent<BoxCollider2D>().enabled = true;
other.GetComponent<CircleCollider2D>().enabled = true;
}
}
}
Im suspecting that it is because the OnTriggerExit2D function is not checking the collider of the OTHER portal and is instead checking itself (script is attached to both portals). How do I make the on OnTriggerExit2D function check the other portal instead?