I have this code and the editor is throwing this error message: MissingComponentException: There is no ‘Animator’ attached to the “Card1” game object, but a script is trying to access it.
However this is my code and the game object should have the name “MulliganCard1” not “Card1”; m contains the string “Card1”.
foreach(string m in MulliganCard)
{
char last = m[m.Length - 1];
Debug.Log(m);
GameObject.Find("Mulligan" + m).GetComponent<Animator>().SetTrigger("Mulligan" + last.ToString() + "Back");
}
I think the core of your problem here is your setup. Its a pretty bad idea to always find objects, since as its name suggests it involves searching for objects within your scene which can be slow.
The main reason to avoid it though is its really prone to bugs, you accidently rename something then you have a ton of bugs. Instead you should had a card manager that holds onto a reference to your cards and have a variable for if its a mulligan.
So:
cardManager.cards.isMulligan
You can then expand this to your components. GetComponent works in a similar way to find, its not the fastest and is also error prone as your seeing. You should have it exposed as a public variable and assign the animator object in the inspector so then you can do: