I am using 2019.3.1f1 and I am having some strange issues. I’m trying to make a portal and I’m using triggers to do it. Here’s the script I’m using:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PortalScript : MonoBehaviour
{
public bool portalActive;
public PortalScript LinkedPortal;
public Transform LinkedPoint;
AudioSource _audio;
public ParticleSystem TeleportEffect;
private void Awake()
{
_audio = GetComponent<AudioSource>();
}
private void OnTriggerEnter(Collider other)
{
if(portalActive)
{
Debug.Log(other.name + " has entered bounds of " + name);
if (other.CompareTag("Player"))
{
if(other.GetComponent<Player2DControl>().useWorldInteraction)
{
_audio.Play();
LinkedPortal.portalActive = false;
Instantiate(TeleportEffect, other.transform);
other.transform.position = LinkedPoint.position;
}
}
}
}
private void OnTriggerExit(Collider other)
{
Debug.Log(other.name + " has left bounds of " + name);
if (other.CompareTag("Player"))
{
portalActive = true;
}
}
}
When the player presses the up button, useWorldInteraction is set to true. What’s strange is when the Player collider enters the trigger, it sends the debug message multiple times, like in a rapid fire sense. I’m not sure why either because the collider isn’t being activated/deactivated and there is only one collider on the player that is in the layer being detected. The OnTriggerExit NEVER activates. The player leaves the trigger upon moving out of it, but the function is never called. Is OnTriggerExit broken or what? In my experience, OnTriggerEnter/Exit only executes ONCE when an object enters or exits the Trigger, right? This seems like a bug.