- Home /
Change boolean after Animation is done
I guess this is a rather basic Question and probably an easy one to solve... but never the less I can't figure it out:
So I got this Animation for my 2D character to move, and I want a boolean to change after the animation is done.
It looks something like this: (This script refrences to my main one)
if ((mainScript.toRight)&&(mainScript.walk))
currentAnimationType = AnimationType.WalkRight;
randomBoolean = true; // after the animation finished
But it doesn't seem to work that way...
Any advice? :)
This is not enough to go on. What exactly does currentAnimationType = AnimationType.WalkRight;
do? What mechanism controls the animation?
I have listed all frames of the animation (4) in a List.
This is the majority of the code:
public List<Texture2D> animationWalkRight;
public float speed = 5;
public enum AnimationType
{
WalkRight,
...
}
void SetTexture(List animationSprite) {
int index = (int)(Time.time * speed);
index = index % animationSprite.Count;
renderer.material.mainTexture = animationSprite [index];
}
public void SetAnimation(AnimationType animationType)
{
currentAnimationType = animationType;
}
void Start () {
mainScript = GetComponent<Player$$anonymous$$ove> ();
}
void Update () {
if ((mainScript.toRight)&&(mainScript.walk))
currentAnimationType = AnimationType.WalkRight;
switch (currentAnimationType)
{
case AnimationType.StayRight:
SetTexture(animationStayRight);
break;
}
}
So every anoimation is made of for Frames.
Hope that that is enough information :)
Thanks for helping
(I have more code, the same thing for every Animation but I think that is clear)
This starts the animation, but there is nothing to ever stop it
if ((mainScript.toRight)&&(mainScript.walk))
currentAnimationType = AnimationType.WalkRight;
I assume (because walking seems continuous, like a button press) you can add something like
else
currentAnimationType = AnimationType.Idle;
And make your idle animation (state and textures).
Answer by edcarlo · Jan 09, 2014 at 03:42 AM
on your script create function animationEnded. or whatever name you want. then create animationEvent at the very last keyframe then select your animationEnded function on the dropdown list. inside that function change your bool varaible to true/false
Does the script need to be on the animated object? I made a public function in another script but cant access it through animation window Even dropdown
Your answer
Follow this Question
Related Questions
Accept All int Values 1 Answer
Set boolean to false when animation changes? 1 Answer
C# | How to detect the end of an animation? 1 Answer
Multiple Cars not working 1 Answer