【问题标题】:How to stop animator如何停止动画师
【发布时间】:2015-07-10 22:25:36
【问题描述】:

当我将手指从 D 键上移开时,我想停止精神的动画,动画师是当你使用像这样的图像时自动制作的那个

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

    }
}

【问题讨论】:

    标签: c# animation unity3d 2d


    【解决方案1】:

    尝试将动画组件的速度设置为 0。 您还需要提供动画剪辑名称。

    这是一个例子:

     Animation animation = GetComponent<Animation>();
     string animationClipName = "1";
    
     animation[animationClipName].speed = 0;   
    

    【讨论】:

    • 想解释一下该代码在做什么,或者它如何解决 OP 的问题?仅代码的答案被认为是低质量的。
    • 别担心...今晚我会解释 :)
    猜你喜欢
    • 1970-01-01
    • 2022-07-13
    • 2016-03-27
    • 2012-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-14
    • 1970-01-01
    相关资源
    最近更新 更多