美文网首页
unity 暂停Animation时,恢复到开始位置

unity 暂停Animation时,恢复到开始位置

作者: WOTTOW | 来源:发表于2020-07-15 16:14 被阅读0次
    
    public class ClickDoor : MonoBehaviour
    {
        public Animation _animation;
        private bool state = false;
        private AnimationState animationState; 
        private void Start()
        {
            _animation = GetComponent<Animation>();
            foreach (AnimationState state in _animation)
            {
                animationState = state;
            }
        }
    
        public void PlayDoorAnimation()
        {
            if (!state)
            {
                _animation.Play();
            }
            else
            {
                animationState.time = 0;
                _animation.Sample();
                _animation.Stop();
            }
            state = !state;
        }
    
        void OnMouseDown()
        {
            PlayDoorAnimation();
        }
    }
    
    
    image.gif

    相关文章

      网友评论

          本文标题:unity 暂停Animation时,恢复到开始位置

          本文链接:https://www.haomeiwen.com/subject/vkcjhktx.html