List wont appropriately add objects.
Hi All,
So I am trying to create a script which iterates through all of the scene game objects and if they have certain components, then they are added to a list which is later used for further processing. Currently the issue:
I have two AudioSource components, each with different AudioClips
Through debugging with print statement, I can see that Clip#1 is added x2 to the list, as opposed of clip#1 and clip #2 being x1 in list.
I am using an AudioStreamIDList.Add command to add to a pre-declared list below my namespace.
private void FindComponents()
{
GameObject[] AllObjects = FindObjectsOfType<GameObject>();
for (int i = 0; i < AllObjects.Length; i++)
{
if (AllObjects[i].GetComponent<AudioSource>() != null)
{
AudioStreamIDList.Add("signal:" + AllObjects[i].GetComponent<AudioSource>().clip.name);
print(i);
print(AudioStreamIDList[i]);
}
}
XmlGenerator();
}
Answer by JollyJumpingBean · Feb 05, 2019 at 11:26 AM
Issue solved!
in array AllObjects clip#2 is in element #6 but in list AudioStreamIDList clip #2 is in element #2
Solved by adding following code in order to keep the array and list in sync
else
{
AudioStreamIDList.Add("N/A");
}
Your answer
Follow this Question
Related Questions
AI to shoot other AI 1 Answer
Endless Runner with new Biome each time 0 Answers
Anyone wanna help? 0 Answers
I have to compare the int of 2 Lists 0 Answers