Enabled and Disabled animators inentire scene???
I'm trying to set all animators in my scene to disabled and then with a button set all animators to enabled. I have use the script below if one or two game objects are animating but now I would like to start & stop all animation with one button.
using UnityEngine;
using System.Collections;
public class AnimWrap : MonoBehaviour
{
public GameObject Worker001;
public GameObject Worker002;
public GameObject Worker003;
void Start ()
{
Worker001.GetComponent<Animator> ().enabled = false;
Worker002.GetComponent<Animator> ().enabled = false;
Worker003.GetComponent<Animator> ().enabled = false;
}
public void AnimatorButton(string AnimOn)
{
Worker001.GetComponent<Animator> ().enabled = true;
Worker002.GetComponent<Animator> ().enabled = true;
Worker003.GetComponent<Animator> ().enabled = true;
}
}
Answer by vintar · Jan 15, 2016 at 10:12 PM
You could do something like this :
public void AnimatorButton(bool animOn)
{
Worker001.GetComponent<Animator> ().enabled = animOn;
Worker002.GetComponent<Animator> ().enabled = animOn;
Worker003.GetComponent<Animator> ().enabled = animOn;
}
Answer by Boggs · Jan 19, 2016 at 09:35 PM
I like it, what you have is more optimized then my code. I was wondering if there's a code that will start or stop all animators in a scene at once without coding for each object. For example my scene might have 50 game objects with animators I would like to avoid coding "worker001 thru worker050.
Your answer
Follow this Question
Related Questions
How to set a special prefab in a switch? 1 Answer
Rotate character 0 Answers
How do i fix this problem 1 Answer
Help with a C# script .SetActive 1 Answer
How to add animations to character ? 0 Answers