• 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
Question by stephen_george98 · Jun 12, 2016 at 07:00 AM · animationanimatorplayerbooleanplayer movement

Make Animation Play After Boolean is Set to True?

Hello all,

I am pretty fluent in using Unity, but regarding Mechanim and Animations I am not the too great at currently, so please don't give me too much of a hard time lol. So I have this boolean that is in my GameManager script :

  public bool countDownDone = false;

This boolean gets set to true once my "3,2,1, GO!" Countdown Timer ends at the beginning of my game. Everything in my game starts after that boolean is set to true. Example:

 using UnityEngine;
    using System.Collections;
 
    public class PlaneMover : MonoBehaviour {

 private GameManagerScript GMS; // Reference to my GameManager Script

 public float scrollSpeed;
 public float tileSizeZAxis;
 public float acceleration; //This has to be a negative number in the inspector. Since our plane is coming down.
 
 private Vector3 startPosition;

 void Start () {

     GMS = GameObject.Find ("GameManager").GetComponent<GameManagerScript> (); //Finds the Script at the first frame

     // Transform position of the quad
     startPosition = transform.position;
 }
 
 void Update () {
     
     if (GMS.countDownDone == true) //Everything starts once the countdown ends. 
     {

         /* Every frame - time in the game times the assigned scroll speed 
             and never exceed the length of the tile that we assign */
         float newPosition = Mathf.Repeat (Time.time * scrollSpeed, tileSizeZAxis);

         // New position equal to the start position plus vector3forward times new position
         transform.position = startPosition + Vector3.forward * newPosition; // was vector3.forward

         scrollSpeed += Time.deltaTime * acceleration; // This makes the plane increase in speed over 
                                                       //  time with whatever our acceleration is set to.
 
     }
 }
 }

I have this Crawling animation that plays at the very beginning of the game (Even before the Timer ends) and loops forever. My question is , how do I make that crawling animation also start once that boolean is set to "true"? Or do I just apply it to a CoRoutine and make it play after 3 seconds? I have done extensive research on whether to reference Animation or Animator and I got confused on that too. Any advice? If you need more pictures or details on my question, just let me know. Thank you! :) alt text

animation.png (25.7 kB)
Comment

People who like this

0 Show 2
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 UsmanAbbasi · Jun 12, 2016 at 10:24 AM 1
Share

Post your animator controller screenshot with transitions and parameters.

avatar image stephen_george98 UsmanAbbasi · Jun 12, 2016 at 10:09 PM 0
Share

alt text

alt text

@UsmanAbbasi There are no transitions or parameters in this scene. That is the only Character Animation that is playing in the scene. It is on loop to keep on repeating itself. All of the movement I programmed to just be manipulated with the transform of the character.

animation-2.png (64.3 kB)
animation-3.png (53.9 kB)

2 Replies

  • Sort: 
avatar image
Best Answer

Answer by UsmanAbbasi · Jun 12, 2016 at 10:28 AM

@stephen_george98 If there is only one state or even if you have more states this is the way you should delay the animations. You should deactivate the "Animator" component in inspector by default, then after the countdown ends activate the "Animator" component like this:

 public Animator animator;
 
 void StartAnimations()
 {
     animator.enabled = true;
 }

Pass animator reference in variable "animator" and call "StartAnimations()" function when countdown is completed.

Comment
stephen_george98
dreg_master

People who like this

2 Show 0 · 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

Answer by husainhz7 · Jun 12, 2016 at 01:19 PM

Well you haven't posted a pic of your animation controller. But in there, you have to make a transition from an "idle" animation to your desired one. Then you need a Boolean parameter there which you can set in your code true when ever you need it.

Sorry if I'm not clear, ask my if you don't get it

Read more here: http://docs.unity3d.com/Manual/AnimationParameters.html

Comment

People who like this

0 Show 1 · 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 stephen_george98 · Jun 13, 2016 at 02:46 AM 0
Share

@husainhz7 I posted a picture of my animator controller above :)

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta on June 13. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Jump animation anticipation 2 Answers

4.3 2D (Need help with Animator in java) 1 Answer

My animation is overriding my character movement? 2 Answers

Having some animation trouble 2 Answers

Add a bool to animator & activate by key press 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