Good day!
I just want to ask, because What I am doing here is if the ray hit an object I am iterating in the list for each object there, then i compare if it the actual object, then I assign some properties. Do I have to do this or I can just access the hit object from the ray?
RaycastHit hit;
Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
Transform objectHit = hit.transform;
if (objectHit.tag == "rack_area" && !mouseOverGUI)
{
foreach (GameObject go in rackList)
{
if (go != null)
{
if (hit.transform.name == go.transform.name)
{
DeselectRackLevel();
go.GetComponent<MaterialHandler>().SetMaterial(1);
tempName = go.transform.name;
tempPosition = go.transform.position;
tempRotation = go.transform.rotation;
initializeAngle = true;
spawnAreaSelected = true;
rackSectionConfigWindowEnabled = false;
rackBaseConfigWindowEnabled = true;
}
else
{
go.GetComponent<MaterialHandler>().SetMaterial(0);
}
}
}