- Home /
Check for an ongoing array of animators?
So, i have an Array of animators, which i intended to use to trigger the same animation of several game objects at the same time. The problem is, i cant really check if there is already an animation/a transition already going on. The reason i dont wanna use ( if anim[].GetCurrentAnimatorStateInfo(0).normalizedTime > 1 && !anim.IsInTransition(0)) inside On() is that it could trigger the animation on some of the objects but not others, and i would like to make them all either animate or not animate(and also bcus the whole script is checking for so much stuff, i would like to not make it any dirtier), but if i cant get to a solution then i guess i'll use it. Here's a snippit of the code:
if (anim[].GetCurrentAnimatorStateInfo(0).normalizedTime > 1 && !anim[].IsInTransition(0)) //line doesnt work, have to specify a value of the array
{
On();
}
void On()
{
for (int i = 0; i < anim.Length; i++)
{
anim[i].Play("DoorClose");
}
//anim.Play("DoorClose");
}
Sorry if the way i phrased it is too confusing...
I would suggest you use a boolean for the doors opening and closing instead of .play
Not sure what you mean or how that would help...
The problem evolved... kinda. I found a "solution", now the animation check doesnt work and i have no clue why.
public class SimpleButton : $$anonymous$$onoBehaviour
{
public bool on;
private float range;
public GameObject activated;
public GameObject deactivated;
public GameObject player;
public Animator[] anim;
// Start is called before the first frame update
void Start()
{
range = 5;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.E) && (player.transform.position - transform.position).sqr$$anonymous$$agnitude < range * range && !on)// /?
{
AnimCheck();
if (AnimCheck())
On();
}
else if (Input.GetKeyDown(KeyCode.E) && (player.transform.position - transform.position).sqr$$anonymous$$agnitude < range * range && on)// /?
{
AnimCheck();
if (AnimCheck())
Off();
}//else if (Input.GetKeyDown(KeyCode.E) && (player.transform.position - transform.position).sqr$$anonymous$$agnitude < range * range && on && anim[].GetCurrentAnimatorStateInfo(0).normalizedTime > 1 && !anim.IsInTransition(0))// /?
}
private bool AnimCheck()
{
for (int i = 0; i < anim.Length; i++)
{
if (anim[i].GetCurrentAnimatorStateInfo(0).normalizedTime <= 0 && anim[i].IsInTransition(0))
{//should do: checks if animation is playing then check if it is transitioning
return false;
}
}
return true;
}
void On()
{
for (int i = 0; i < anim.Length; i++)
{
anim[i].Play("DoorClose");
}
on = true;
Instantiate(activated, new Vector3(transform.position.x, transform.position.y + 2, transform.position.z), activated.transform.rotation);
}
void Off()
{
for (int i = 0; i < anim.Length; i++)
{
anim[i].Play("DoorOpen");
}
on = false;
Instantiate(deactivated, new Vector3(transform.position.x, transform.position.y + 2, transform.position.z), deactivated.transform.rotation);
}
}
At this point im unsure i can be helped, but im persistent af
@LulaCD it appears that you are not getting a value from your animcheck such as animCheck(true) or animCheck(false)
Your answer
Follow this Question
Related Questions
Conflicting Animator SetTrigger 0 Answers
2D Animation does not start 1 Answer
Copy the exact "state" of an Animator / RuntimeAnimatorControler to another Object 0 Answers
Animation Finishes Sequence Before Going To Next Animation 1 Answer
Playing An Animation At A Certain Point Based On Mouse Position 0 Answers