Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
2
Question by Xdimx · Oct 26, 2016 at 02:49 PM · scripting problemanimatorplay

Play animation with script

Spent 3 days of trying create simple animation of sphere... but no result. Please, said what's wrong with this script?

anim.Play doesn't work

but if I change it to anim.Stop -- it works.

 using UnityEngine;
 using System.Collections;
 
 public class sphereScript : MonoBehaviour {
 
     public Animator anim;
 
     void Start() {
         anim = GetComponent<Animator>();
         anim.Stop();
     }
     
 
     void Update () {
         anim.Play("sphereAnimation");
     }
 }
Comment
Add comment · Show 1
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 crare · Jan 29, 2018 at 07:13 PM 1
Share

Animator.Play() function starts the animation. You are calling that every Update(). So the animation might start playing every frame, but it might not seem to play because it's starting again every frame. Try to call it once in Start() function and see what happens. Or you could put it inside if statement of pressing space for example:

 void Update() {
     if(Input.get$$anonymous$$eyUp($$anonymous$$eyCode.Space)) {
         anim.Play("sphereAnimation");
     }
 }

documentation ca be found here: https://docs.unity3d.com/ScriptReference/Animation.Play.html

3 Replies

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

Answer by AurimasBlazulionis · Oct 26, 2016 at 03:55 PM

You have to create transitions. Most likely you will have to have a default animation without any motion applied. And a transition to an animation with a boolean or trigger as a parameter. Then you should do anim.SetBool("theParameter", true). A single answer can not explain everything, you should better watch this video made by Unity themselves.

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 Xdimx · Oct 26, 2016 at 04:23 PM 0
Share

thank you! I have already seen this video, but it's not easy to understand.

I have simple motion in my animation, it's only changing position of Sphere.

Is it a chance to Play this kind of animation without a transition? (like Adobe Flash do ;) )

avatar image AurimasBlazulionis Xdimx · Oct 26, 2016 at 05:15 PM 0
Share

You can use a legacy Animation component. That is simpler, or if it is even simpler you can just set position.

avatar image
0

Answer by Tim-Duval · Nov 25, 2018 at 11:24 PM

 if (Mathf.Abs(player.velocity.x) > 0  && onFloor==true)
         {
 
            
             anim.SetBool("Idle", false);
             anim.SetBool("Walk", true);
         }
         else if(Mathf.Abs(player.velocity.x) == 0  && onFloor==true)
         {
 
            
             anim.SetBool("Walk", false);
             anim.SetBool("Idle", true);
 
         }

Ok, so I've tried this. I have all transition lines set to either true/false. Can you tell me what I'm doing wrong and why this isn't working?

Comment
Add comment · 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
0

Answer by rahulnaik9010 · Aug 28, 2020 at 02:26 PM

Don't put anim.Play("sphereAnimation"); inside the Update() Method.This will call the play animation in every frame. Put anim.Play("sphereAnimation"); in a single call.

Comment
Add comment · 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

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

96 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 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 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 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 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

BCE0020 error with animation 1 Answer

Animator does not show up 0 Answers

Animation not consistent 0 Answers

Animations in a blend tree. 0 Answers

Help please, movement and animator issue 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