- Home /
Why isn't my Physics.CheckBox working?
I'm relatively new to coding in C# and using Unity. I've got a basic understanding of the language and I do have previous experience in Python. I'm currently developing a more complicated 2D version of battleships and am currently developing the placement process of each ship. My issue is with the Physics.CheckBox function. It appears it's not detecting the colliders on my sprites. This excerpt is from my script which is attached to the selectionManager which is supposed to detect if any ships are below it.
//Place object
if (Input.GetMouseButtonDown(0))
{
Vector2 mouseRay = Camera.main.ScreenToWorldPoint(templateObject.transform.position);
if(Physics.CheckBox(mousePos, new Vector3(1,2,Mathf.Infinity), templateObject.transform.rotation, allTilesLayer) == false)
{
Instantiate(finalObject, templateObject.transform.position, templateObject.transform.rotation);
}
}
if (Physics.CheckBox(mousePos, new Vector3(1, 2, Mathf.Infinity), templateObject.transform.rotation, allTilesLayer) == true)
{
templateObject.GetComponent<Renderer>().material.color = Color.red;
}
else
{
templateObject.GetComponent<Renderer>().material.color = Color.green;
}
}
Also, any suggestions to improve the efficiency or overall structure of my code is welcomed.
Comment