Hi,
I have two types of objects in my scene. GameObject Blockers and GameObject Meshes. If there is a Blocker object right on top of Mesh object I want Mesh object to change material. Blockers objects are moveable, so I want to execute this in Update().
But this function only works in Start() and in Update() only works on 1 object. Even though I checked, and for 2 Blockers, contition “occupied” returns true for 2 Meshes. But function SetMaterialsHere() executes only on 1 object.
So first question: why is that?
And second: is it a good way to change materials? Do I realy want this code to run every frame? Wont this slow down my game?
void Action(GameObject[] Blockers, GameObject[] Meshes)
{
foreach (GameObject b in Blockers)
{
foreach (GameObject m in Meshes)
{
Vector3 positionToCheck = b.transform.position + Vector3.down;
bool occupied = m.transform.position == positionToCheck;
if (occupied)
{
SetMaterialsHere();
}
}
}
}