2015-07-10 157 views
0

我想停下來精神的動畫,當我從d鍵刪除我的手指,動畫製作是當你使用像這樣的The Picture!如何停止動畫

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); 
     } 

    } 
} 

回答

0

嘗試設置是自動進行的一個動畫組件的速度爲0. 您還需要提供動畫剪輯名稱。

下面是一個例子:

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

animation[animationClipName].speed = 0; 
+0

護理解釋那是什麼代碼做什麼,或者它如何解決了OP的問題?僅有代碼的答案被認爲是低質量的。 –

+0

你不用擔心......今晚我會解釋一下:) –