Reputation: 67
I want to stop to animation of a spirit when I remove my finger from the D key,The animator is the one that made automatically when you use image like that
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
// Use this for initialization
public GameObject main_camera;
void Start () {
main_camera = GameObject.FindGameObjectWithTag("MainCamera");
}
// Update is called once per frame
void Update () {
if (Input.GetKey (KeyCode.D)) {
transform.Translate(Vector3.right * 1*Time.deltaTime);
main_camera.transform.Translate(Vector3.right * 1*Time.deltaTime);
}
if (Input.GetKeyUp (KeyCode.D)) {
//WANT ANIMATION TO STOP
Animator.speed(0);
}
}
}
Upvotes: 0
Views: 115
Reputation: 67
Try setting the speed of the Animation component to 0. You will need to provide the animation clip name as well.
Here is an example:
Animation animation = GetComponent<Animation>();
string animationClipName = "1";
animation[animationClipName].speed = 0;
Upvotes: 1