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 arturoza · Jun 15, 2015 at 12:23 AM · animationspeedpauseplay

Animation ["1"].speed = 0; Doesn't work

Hi, I was trying to start an animation stopped and play it when I press a button, so far I got this:

 using UnityEngine;
 using System.Collections;
 
 public class animatorcotrols : MonoBehaviour {
     
     void Sart() 
     {
         Animation ["1"].speed = 0;
     }
 
     void OnGUI()
     {
         if(GUI.Button(new Rect(0, 0, 100, 100), "Debug!"))
         {
             Animation ["1"].speed = 1;
         }
     }
 
 }

But it says

Assets/animatorcotrols.cs(8,17): error CS0119: Expression denotes a type', where a variable', value' or method group' was expected

I don't know if I should use this function or is there a better way to do this, I've searched everywhere and I can't find the solution, the worst part is that I've done this before and it's extremely simple but I just can't, thanks for your help in advance.

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 arturoza · Jun 15, 2015 at 12:34 AM 0
Share

Edit: I think quotes are not supposed to be there, but still mark it as an error.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Cherno · Jun 16, 2015 at 01:11 AM

You have to reference a specific animation clip:

 Animation animation = GetComponent<Animation>();
 string animationClipName = "1";

 animation[animationClipName].speed = 0;

Of course, this means that you will only see the result when you actually play the clip.

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 devluz · Jun 15, 2015 at 12:39 AM

Animation is a class and you are trying to use it like an object. If you want to access the Animation connected to a unity object you have to do it like this:

 Animation animation = GetComponent<Animation>();
 animation.speed = 1;

I am not sure if this still works though. I didn't work with the Animation class for years. You should have a look at the tutorials:

https://unity3d.com/learn/tutorials/modules/beginner/animation

Comment
Add comment · Show 5 · 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 arturoza · Jun 15, 2015 at 12:52 AM 0
Share

It doesn't work, but maybe I'm doing it wrong, would you $$anonymous$$d to illustrate how exactly should I write the script, thank you so much.

avatar image incorrect · Jun 15, 2015 at 12:58 AM 1
Share

@agoarturoza, there is an Animator component that was introduced ins$$anonymous$$d of old Animation. You still can use Animation, but if you have Animator attached to your object obviously the code above will not work.

avatar image arturoza · Jun 15, 2015 at 01:00 AM 0
Share

Hi! thanks for your help, unfortunately I'm new in this so I'm not pretty sure about what did you mean, would you $$anonymous$$d to explain it with more details. thank you so much.

avatar image devluz · Jun 15, 2015 at 01:50 AM 0
Share

Sorry but that is a bit too much. There are plenty tutorials for that. Checkout the link in my answer.

avatar image arturoza · Jun 15, 2015 at 11:20 PM 0
Share

Ok, don't worry but I've tried plenty of tutorials and I still can't figure it out.

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

23 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

Related Questions

[Unsolved] Playing animation backwords [Unsolved] 1 Answer

Creating a play/pause button for animations. 0 Answers

Animation Stop and Stay 1 Answer

How do I combine a GUI scroll with an animation? 1 Answer

I am attempting to play an animation in reverse and slow it down, But it only seems to play forwards. 2 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