public class Surroundings : MonoBehaviour {
List <GameObject> collidedWith = new List<GameObject>();
void OnTriggerEnter(Collider col)
{
collidedWith.Add(col.gameObject);
}
void OnTriggerExit(Collider col)
{
collidedWith.Remove(col.gameObject);
}
public List<GameObject> GetArray()
{
return collidedWith;
}
}
This is my code on each “Stone” objects in the scene. This is supposed to return a list of colliding objects.
public class toBeDestroyed : MonoBehaviour
{
GameObject[] allStones;
void Permission(bool perm)
{
if (perm)
{
allStones = GameObject.FindGameObjectsWithTag("Stone");
Begin();
}
}
void Begin()
{
foreach (GameObject go in allStones)
{
print("Prints this.");
foreach (GameObject go2 in go.GetComponent<Surroundings>().GetArray())
{
print("Doesn't print this.");
}
}
}
}
And this script has to check that array of colliders. As you can see, second foreach is trying to access that list which isn’t happening. I tried to print “go.GetComponent().GetArray().Count” and it printed out 0 although those go objects sure had colliding objects.
All objects in my scene have rigid bodies with “is kinematic” enabled, collision detection using continuous and they have colliders with “is trigger” enabled. I used to return those values with no problem before. I haven’t checked my project in a few days and when I was back, bam : problem.
So what could be the problem? Thanks in advance.