I am trying to create doodle jump like game with object pool for platforms. I have created an empty object with box 2D collider attached to it. This object moves with player and should be gathering platforms which exit its collider, but it isn't.
public class PoolGrabber : MonoBehaviour {
[Tooltip("Field for game manager.")]
[SerializeField]
private GameObject gameManager;
private void Awake()
{
gameManager = GameObject.FindGameObjectWithTag("GameManager");
}
private void OnTriggerExit2D(Collider2D collision)
{
if(collision.tag == "PooledObject")
{
collision.gameObject.SetActive(false);
gameManager.GetComponent<LevelGenerator>().objectPool.Add(collision.gameObject);
}
}
It also doesn't work with OnTriggerEnter2D.
I have also tried
private void OnBecameInvisible()
{
gameObject.SetActive(false);
}
on a platform. Doesnt work either.
I have discovered that for all those methods above object required to has Rigidbody2D component. But what if I don't want any phisycs calculations to be handled. I don't need physics on those platforms at all. Also, an object doesn't become invisible if you see it in the editor window. Isn't very convenient.