zoukankan      html  css  js  c++  java
  • c#4

    	

    float translation = Time.deltaTime * 10; transform.Translate(0, 0, translation);//沿z轴移动

     

    public class AutoDestoryComponent : MonoBehaviour 

        #region ICanCache 
        public ParticleSystem[] m_pss = null; 
        public int m_life = 1; //3条命 
        public float m_AutoDeadTime = 3;//3s自动销毁

        private int m_life_Base = 3; //3条命【恢复用】 
        private float m_AutoDeadTime_Base = 3;//3s自动销毁【恢复用】【-1:表示不自动销毁,如Enemy】

        void Update() 
        { 
            //需要自动销毁 
            if (m_AutoDeadTime_Base >= 0) 
            { 
                m_AutoDeadTime -= Time.deltaTime;//每一帧减去一个Time.deltaTime

                if (m_AutoDeadTime <= 0) 
                { 
                    InnerDead(); // 物体销毁
                    return; 
                } 
            }

            if (m_life <= 0) 
            { 
                InnerDead(); //玩家死亡
            } 
        }

        /// <summary> 
        /// 设置自动销毁数据 
        /// </summary> 
        /// <param name="life_base">默认生命值</param> 
        /// <param name="autoDeadTime_base">-1不自动销毁;其他数据代表销毁时间(单位s)</param> 
        public void SetBasePara(int life_base = 1, float autoDeadTime_base = -1) 
        { 
            m_AutoDeadTime = m_AutoDeadTime_Base = autoDeadTime_base; //用来恢复时间
            m_life = m_life_Base = life_base; //用来恢复初始生命
        }

        //是否启用 
        public bool IsUse { get; set; } 
        //死后位置 
        public Vector3 DeathPosition 
        { 
            get 
            { 
                return new Vector3(2000, 2000, 2000); //返回新位置Vector3(x,y,z)
            } 
        }

        //复活 
        public void Init(Vector3 position, Quaternion rotation) 
        { 
            transform.gameObject.SetActive(true); 
            transform.position = position; 
            transform.rotation = rotation; 
            IsUse = true; 
            foreach (ParticleSystem item in m_pss) 
            { 
                item.Play(true); 
            }

            //有些绕 
            m_life = m_life_Base; 
            m_AutoDeadTime = m_AutoDeadTime_Base; 
        }

        private void InnerDead() 
        { 
            IsUse = false; 
            transform.position = DeathPosition; 
            foreach (ParticleSystem item in m_pss) 
            { 
                item.Stop(true); 
            }

            this.gameObject.SetActive(false); 
        } 
        #endregion 
    }

  • 相关阅读:
    WPF 登录窗口关闭时打开主窗口
    WPF Expander获得ToggleButton
    .NET Framework 4 与 .NET Framework 4 Client Profile
    WPF 根据枚举值名称 获得枚举值
    WPF KeyDown不响应方向键、Home/End/PgUp/PgDn等功能键
    C# MemoryStream和BinaryFormatter
    VB INET控件的全部用法
    C#写文件方法总结
    C#实现ADSL拨号(源代码例程)
    使用C#实现ADSL自动拨号(原理及封闭类)
  • 原文地址:https://www.cnblogs.com/wshyj/p/6094229.html
Copyright © 2011-2022 走看看