I want to check if the position I generated has another object or not. iI do this by using Raycast ;:
private void RandomOBS()
{
Vector3 pos = new Vector3(UnityEngine.Random.Range(-8f, 8f), UnityEngine.Random.Range(-4f, 4f), 0);
while (Physics2D.Raycast(pos, pos).collider)
pos = new Vector3(UnityEngine.Random.Range(-8f, 8f), UnityEngine.Random.Range(-4f, 4f), 0);
}
The code above doesntdoesn't work at all. iI tested it with if statement and for some reason it cannot check that position.
private void RandomOBS()
{
Vector3 pos = new Vector3(UnityEngine.Random.Range(-8f, 8f), UnityEngine.Random.Range(-4f, 4f), 0);
while (Physics2D.Raycast(transform.position, transform.position).collider)
pos = new Vector3(UnityEngine.Random.Range(-8f, 8f), UnityEngine.Random.Range(-4f, 4f), 0);
}
howeverHowever when you check the transform.positiontransform.position instead of the pospos, it works?!? how How and why. all? All the game objects have the correct colliders & stuff.