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
0
Question by aronatvw · Nov 26, 2013 at 03:21 AM · animationanimatorstopplayback

Trying to code a simple animation, please help.

I made an animation it just changes between two different materials. I play the animation each time a prefab is called using getcomponent on the prefab, that seems to be working fine. My problem is I am not very fluent with the animator, and it plays all my animations right in the beginning of the scene. I try using animation.stop and animator.stopplayback I cant figure out how control the animator. I know its probably some check box, please forgive me if the answer is simple I am new! :-/

Comment
Add comment · Show 3
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 Commander Quackers · Nov 26, 2013 at 03:26 AM 1
Share

Can you please share the code? Can't do much without the code. Also give more details about what you're trying to accomplish.

avatar image aronatvw · Nov 26, 2013 at 03:42 AM 0
Share

Yes I can in the morning, but I am trying to accomplish a warning animation that an obstacle it's approaching in an infinite runner .

avatar image aronatvw · Nov 27, 2013 at 03:06 AM 0
Share

heres some code the animation auto plays in the beginning of scene so I try to stop it?

 // From Prefab
 
 public class DestroyAtX : $$anonymous$$onoBehaviour {
 
     public float stopanim;
     public float kill;
     private Animator stoploganim;
     public GameObject log;
 
     // Use this for initialization
     void Start () {
 
 
 
         log = GameObject.Find("warn");
         stoploganim = log.GetComponent<Animator>();
 
         stoploganim.Play("GO");
     
     }
     
     // Update is called once per frame
     void Update () {
 
 
         if(transform.position.x < stopanim){
 
             stoploganim.SetTrigger("STOP");
 
 
 
         }
 
         if(transform.position.x < kill){
 
             DestroyObject(this.gameObject);
 
         }
     
     }
 }
 
 // From Plane with animation
 
 public class WarnAnimTest : $$anonymous$$onoBehaviour {
 
     private Animator warnstop;
 
 
     // Use this for initialization
     void Start () {
     
         warnstop = GetComponent<Animator>();
         warnstop.StopPlayback();
 
 
 
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }
 
 

1 Reply

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

Answer by abi-kr01 · Nov 26, 2013 at 12:56 PM

 Well if its only about two material rendering then u can use my code 
 what it basically does is it provide sprite animation, which uses images to play
 you can try it it may work for your project

 
 #pragma strict
 
 class SpriteAnimJS extends MonoBehaviour 
 {
     var frameA                : Texture2D;    //The first frame of the animation
     var frameB                 : Texture2D;    //The second frame of the animation
     
     private var currentId     : int     = 0;    //The ID of the current frame
     private var canAnimate     : boolean     = false; //Animation enabled/disabled
     
     //Called when the object is enabled
     function OnEnable () 
     {
         //Enable the animation
         canAnimate = true;
     }
     //Called when the object is disabled
     function OnDisable()
     {
         //Stop the animation coroutine, and disable the animation
         StopCoroutine("Animate");
         canAnimate = false;
     }
     //Called on every frame
     function Update()
     {
         //If the animation is enabled
         if (canAnimate)
         {
             //Start the animation coroutine
             StartCoroutine(Animate());
         }
     }
     //The animation coroutine
     function Animate()
     {
         //Disable the calling of additional coroutines
         canAnimate = false;
         
         //Wait for 0.1 seconds
         yield WaitForSeconds(0.1f);
         
         //If the current animation frame is 0
         if (currentId == 0)
         {
             //Go to animation frame 1
             this.renderer.material.mainTexture = frameB;
             currentId = 1;
         }
         //If the current animation frame is 1
         else
         {
             //Go to animation frame 0
             this.renderer.material.mainTexture = frameA;
             currentId = 0;
         }
         
         //Enable the calling of a new coroutine
         canAnimate = true;
     }
 }
Comment
Add comment · 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 aronatvw · Nov 26, 2013 at 03:06 PM 0
Share

Cool, I'll check it out. Originally I was going that route and for some reason tried the animator route. The animator is a pain to control via code though. I simply want " if this happens ( either s function is invoked or a trigger is hit) then this animation will play."

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

18 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

Related Questions

Stop Animation State in Animator from Speeding Up after Playing it a Second Time? 0 Answers

2D Animation does not start 1 Answer

Should I use playables, mecanim, or legacy to create keys and clips ? 0 Answers

GUI button is moving/disappearing when animation is played 0 Answers

How to end an animator animation using time? 0 Answers


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