Hello, I’m working on Loading and Saving for my game and I need to assign Materials back to GOs. I have a loop after loading that assigns the materials back to the loaded GOs using a list of Strings that is saved.
The for loop goes through the GOs and uses the Material list to assign mats using the String from the saved Materials names list.
But whenever the loop runs it uses the Material every material from the list, ending on the final material. Is there a way to get a Material from the list without using a Foreach Loop?
for (int i = 0; i < GOobj.Count; i++)
{
foreach (string matName in matNames)
{
foreach(Material matDB in this.gameObject.GetComponent<itemDataBase>().mats)
{
if (matDB.name == matName.Trim())
{
plaster*.gameObject.GetComponent<MeshRenderer>().material = matDB;*
}
}
}
}
I just need to get the correct Mat from the list. I thought that the line
if (matDB.name == matName.Trim())
would make sure the correct Material is used and not all of them.
Does this make sense?
Thank you for any help.