Exit from OnTriggerEnter doesn't work.

Hello,

I’ve a problem, when I enter in the trigger everything works fine but when I exit from this my character continues to be like if he’s in it. I’ve tried with OnTriggerExit and with OnTriggerStay but it’s the same.
Can you help me please ? :slight_smile:

Here is my code :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Child : MonoBehaviour 
{

[SerializeField]
Transform platform;

	void Start ()
	{
	}

	void OnTriggerEnter2D(Collider2D other)
	{
		if(other.tag == "Player")
		{
			other.transform.parent = platform.transform;
		}
	}
}

@Landern

Here is the code i have now :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Child : MonoBehaviour 
{

[SerializeField]
GameObject platform;

	void Start ()
	{
	}

	void OnTriggerStay2D(Collider2D other)
	{
		if(other.tag == "Player")
		{
			other.transform.parent = platform.transform;
		}
		
		if(other.tag == "Dynamic")
		{
			other.transform.parent = platform.transform;
		}
	}
	
	void OnTriggerExit2D(Collider2D other)
	{
		if(other.tag == "Player")
		{
			other.transform.parent = null;
		}
		
		if(other.tag == "Dynamic")
		{
			other.transform.parent = null;
		}
	}
}

It works well with both “Dynamyc” and "Player objects but sometimes my character still get in the trigger when it should not. i don’t know how to correct it. It does not happen often but it is annoying when it happens.