So I have an object and a script that generates grids. What I want to do is tell me if the object is in a specific area of the grid, and if so for how long. I looked up online for how to detect and found that to approach this with 2D colliders. So I attempted this and played the scene and ultimately it will not work. Is my code wrong. Both the object and the grid have isTrigger box checked on inspector. Just wanted to clarify I am new to unity. Here is the code and a picture of what is happening.
Here is the code for telling if the object is in the grid(The debug also does not show when the object is in grid)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Collide : MonoBehaviour
{
bool isInSection1, isInSection2;
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.name == "GridHolder")
{
isInSection1 = true;
isInSection2 = false;
Debug.Log("Test");
}
else if (collision.gameObject.name=="eye")
{
isInSection1 = false;
isInSection2 = true;
Debug.Log("Test");
}
}
}