Xdimx
October 26, 2016, 10:24am
1
Hello!
Unity 5.4.1
Try to make simple animation of cube. Made it rotation in Animation window (animator controller was added by Unity)
Then I added “Animation component” to Cube.
Then, I added script to Cube:
public Animation myAnimation;
void Start () {
myAnimation = GetComponent<Animation>();
}
void Update () {
myAnimation.Stop("cube_animation2");
}
It didin’t work, and wrote Mark animation as “Legacy” .
I marked it, in Debug mode (is it any other way to do it?)
[80959-снимок1.png|80959]
And after it script is going to work!
But now, if I click on Cube, then there is no animation in Animation window…
[80960-снимок2.png|80960]
Help please! How Can I get it??
If you created an animation and Unity added an 'Animator Controller'
by itself. Then you don’t need to add another Animation
component.
And change your script to this : (Not tested, but should work)
public Animator myAnimation;
void Start () {
myAnimation = GetComponent<Animator>();
}
void Update () {
myAnimation.Play();
//similarly
myAnimation.Stop();
}
Xdimx
October 26, 2016, 12:43pm
3
Thank you very much! Have done exactly what you wrote, but still have a problem.
Create Sphere, make animation, Animator component created by Unity.
[80968-снимок3.png|80968]
Add script.
using UnityEngine;
using System.Collections;
public class sphereScript : MonoBehaviour {
public Animator anim;
void Start() {
anim = GetComponent<Animator>();
anim.Stop();
}
void Update () {
if (Input.GetMouseButton(0)){
print("sphere: I press mouse button");
anim.Play("sphereAnimation");
}
}
}
It Stop playing animation, but doesn’t start it by clicking mouse button…