Duplicated animations between teams

I have two or more instances of the same collection in the scene. Each of them has an animator, and each of them has the same animator controller connected to it. When I animate one of them, they all get the same animation. Any clues on what's happening on earth? Should I have a separate animator for each player on stage? How to separate animators from each other in C #?

+4
source share
2 answers

I will add this as an answer, even if you have not put your code as resources. This will be my bet.

I made a game that also shares the animator with the same prefab files, but if you only call a GameObject that needs to be animated. It should not call other Animator calls. An object runs with different animators every time, even if the Animator file is the same.

To test this, I would suggest that every time you create an instance of your GameObject. Call it something else. eg.

public GameObject[] myPrefabs; //make sure to add the size in the inspector

myPrefabs[0] = (GameObject)Instantiate(nameofPrefab);
myPrefabs[0].name = "myPrefabs0"; // this is to make sure that name (Clone) is removed;

// Then call the animation.
myPrefabs[0].GetComponent<Animator>().SetTrigger("Attack");

// SetTrigger, SetBool, SetInt. Since this is an animator

I use List instead of Array, but I think this is the easiest I can give.

Prefix naming is not required to fix your problem. But you need it so that you can check if this is the correct GameObject that accepts your Animator call

0
source

, . , , . , .

Animator. .

,

Animator animator;

GameObject prefab;
List<GameObject> prefabs;

prefab = (GameObject)Instantiate(Resources.Load("prefabNameinAssets"));
prefab.AddComponent<Animator>(); // add each prefab its own Animator component

animator = prefab.GetComponent<Animator>();
animator.runtimeAnimatorController = (RuntimeAnimatorController)Instantiate(Resources.Load("animatorControllerNameinAssets"));
//get prefab Animator Component and set its controller

prefab.name = "prefabName";
prefabs.Add(prefab);

prefabs . AnimatorControllers.

prefabs[0].GetComponent<Animator>().setTrigger("Animation");
0

All Articles