zoukankan      html  css  js  c++  java
  • 游戏暂停同时角色动作暂停

    需求

    当在游戏暂停的时候,播放的动画也要相应地暂停,游戏暂停写成一个事件

    FramGameManager

    using UnityEngine;
    using System.Collections;
    
    public class FramGameManager : MonoBehaviour
    {
        public static FramGameManager instance;
        public delegate void gamePauseHandler(bool pauses);
        public event gamePauseHandler gamePause;
        
        
        void Awake(){
            instance=this;    
        }
        
        // Use this for initialization
        void Start ()
        {
        
        }
        
        // Update is called once per frame
        void Update ()
        {
        
        }
    }
    
    

    FramPlayAnimation

     
    using UnityEngine;
    using System.Collections;
    
    public class FramPlayAnimation : MonoBehaviour
    {
        private FramGameManager gameManager;
        private Animation thisAnimation;
        bool isPress = false;
        
        // Use this for initialization
        void Start ()
        {
            thisAnimation = animation;
            thisAnimation ["Idle"].wrapMode = WrapMode.Loop;
            thisAnimation ["Idle"].layer = 1;
            thisAnimation.Play ();
        }
    
        void OnGUI ()
        {
            if (GUILayout.Button ("Pause")) {
                isPress = !isPress;
                gamePause (isPress);
            }
        }
        
        public void gamePause (bool pause)
        {
            int speed = pause ? 0 : 1;
            foreach (AnimationState item in thisAnimation) {
                item.speed = speed;
            }
        }
    }
    

    运行效果

    运行结果,当点击暂停时角色动画将暂停

    imageimage

  • 相关阅读:
    数据库
    Xpath表达式
    错误:向非托管代码传递委托时,托管应用程序必须让这些委托保持活动状态,直到确信不会再次调用它们
    xmlhttp status各类Http请求状态(status)及其含义
    配置ckeditor3.0 和ckfinder
    程序默认用管理员身份打开(vs2010)
    (转)CKFinder破解的方法,去掉提示
    无法嵌入互操作类型“SHDocVw.ShellWindowsClass”。请改用适用的接口
    ASP.NET页面执行顺序
    回调函数
  • 原文地址:https://www.cnblogs.com/zhaoqingqing/p/3475236.html
Copyright © 2011-2022 走看看