• 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 mind 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 mind 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

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

Animation Stop and Stay 1 Answer

Set up Animator with specific seconds 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges