- Home /
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.
Edit: I think quotes are not supposed to be there, but still mark it as an error.
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.
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
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.
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.
Sorry but that is a bit too much. There are plenty tutorials for that. Checkout the link in my answer.
Ok, don't worry but I've tried plenty of tutorials and I still can't figure it out.