Hello,
I am trying to check for a collision while a for loop is running. But what ever i try it seems the for loop runs all the way through before it checks for any collisions. I want the xaxis and yaxis to debug.Log when collision occurs while its still in the loop.
public class GrassTile1 : MonoBehaviour
{
public GameObject BoxChecker;
public static int xaxis=0;
public static int yaxis=0;
void OnCollisionEnter(Collision col)
{
Debug.Log(xaxis);
Debug.Log(yaxis);
}
void Start()
{
//spawn box checker
for (int p = 1; p < 11; p++)
{
for (int i = 1; i < 11; i++)
{
GameObject cubeSpawn = (GameObject)Instantiate(BoxChecker, new Vector3(i - 0.5f, p - 0.5f, -0.4f), transform.rotation);
xaxis++;
OnCollisionEnter();//i was thinking i could call the collision method like this but that doesnt work
}
yaxis++;
}
}
}
many many many thanks for answers