Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by SC4V4NGER · Jan 08, 2014 at 09:50 PM · c#animationbooleanbasic

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? :)

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RudyTheDev · Jan 09, 2014 at 12:07 AM 0
Share

This is not enough to go on. What exactly does currentAnimationType = AnimationType.WalkRight; do? What mechanism controls the animation?

avatar image SC4V4NGER · Jan 09, 2014 at 11:39 AM 0
Share

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)

avatar image RudyTheDev · Jan 09, 2014 at 05:18 PM 0
Share

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).

avatar image SC4V4NGER · Jan 09, 2014 at 06:14 PM 0
Share

Thanks for your help :)

1 Reply

· Add your reply
  • Sort: 
avatar image
7
Best Answer

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SC4V4NGER · Jan 09, 2014 at 11:40 AM 0
Share

Thank you :) This worked out for me

avatar image TKDHayk · Jun 01, 2016 at 09:40 PM 1
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

Hi, Im trying to make a sword swing animation, but it is playing non stop how can I make it go back to Idle Animation? 4 Answers

Multiple Cars not working 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges