- Home /
Set All bool parameters in animator to false
Hello human beings!
I want to set all the bool parameters in the animator of an object to false, to then be able to set only the one i want to true without needing to set each parameter prematurely in the editor. I have tried doing that in many different ways but i can't figure out how!
I don't think my code will be any use but:
public Animator timeReflectionAnimator;
public AnimatorControllerParameter[] parameters;
private int posInList = 0;
foreach (AnimatorControllerParameter parameter in parameters) {
if (parameter.type == AnimatorControllerParameterType.Bool) {
timeReflectionAnimator.SetBool (parameter.name, false);
}
}
timeReflectionAnimator.SetBool (animations[posInList].animation, true);
Don't worry about the animations list. it's a struct i made that gets a string and an int (animation, time).
Thank you for every help you can give!
Ethan
Have you considered using triggers ins$$anonymous$$d of bools? they work like a bool but reset to false after the animator uses them in a transition.
Otherwise if you still need to find all the bool parameters in your animator have a look here, it may have what your missing
http://answers.unity3d.com/questions/494966/get-list-of-parameters-of-an-animatorcontroller.html
Not quite sure what you want to do here. What are you doing with posInList? It's not changing from 0 so won't you always get the same animation set to true? Do you want a certain animation from the list to play based on some sort of position within the list of parameters...? scratches head
Answer by BBIT-SOLUTIONS · Jun 09, 2017 at 05:20 PM
Hey @EitanCreate,
I think, this code should work:
foreach(AnimatorControllerParameter parameter in timeReflectionAnimator.parameters) {
timeReflectionAnimator.SetBool(parameter.name, false);
}
Now you can set the one, that should be true, with:
timeReflectionAnimator.SetBool("yourParameterName", true);
Your answer
Follow this Question
Related Questions
How to turn this bool into false? 1 Answer
Animations not Transitioning 0 Answers
How to set an Animator Boolean with JavaScript 1 Answer
Error : Animator has not been initialized. UnityEngine.Animator:SetBool(String, Boolean) 1 Answer
spawns without controller-: Object reference not set to an instance of an object--but i swear it is! 1 Answer