title: Unity C# - When having both OnTriggerExit and OnTriggerEnter, only OnTriggerExit gets called
body: <p>Okay, so I can't see where is my problem. I used OnTriggerEnter for my moving platform. it has rigid body component and the box collider is set to isTrigger on both the platform and player, but for some reason when my platform is triggered by the player, only the OnTriggerExit gets called out . My player is tagged as player in unity... I don't know what to do.</p>
  
  <p>Code:</p>
  
  <pre><code>using System.Collections;
  
  using System.Collections.Generic;
  
  using UnityEngine;
  
  
  
  public class Moving_Platform : MonoBehaviour
  {
      [SerializeField]
      private float _speed = 1.0f;
  
      [SerializeField]
      private Transform _A, _B;
  
      private bool _direction = false;
  
      void FixedUpdate()
      {
          if(transform.position==_A.position)
          {
              _direction = false;
          }
          else if(transform.position== _B.position)
          {
              _direction = true;
          }
  
          if (_direction == false)
          {
              transform.position = Vector3.MoveTowards(transform.position, _B.position, _speed * Time.deltaTime);
          }
  
          if(_direction==true)
          {
              transform.position = Vector3.MoveTowards(transform.position, _A.position, _speed * Time.deltaTime);
          }
      }
  
      private void OnTriggerEnter(Collider other)
      {
  
          if (other.tag == "Player")
          {
             other.transform.parent = this.transform;
          }
      }
  
      private void OnTriggerExit(Collider other)
      {
          Debug.Log("OMFG");
          if (other.tag == "Player")
          {
              Debug.Log("But why!");
              other.transform.parent = null;
          }
      }
  
  
  }
  </code></pre>
  
  <p>All Inspectors</p>
  
  <p><a href="https://i.stack.imgur.com/2Z8GU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2Z8GU.png" alt=""></a></p>
  
  <p><a href="https://i.stack.imgur.com/eHTiU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eHTiU.png" alt=""></a></p>
  
  <p><a href="https://i.stack.imgur.com/EvbPS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EvbPS.png" alt=""></a></p>
  
  <p><a href="https://i.stack.imgur.com/KVaUH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KVaUH.png" alt=""></a></p>