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 
}

随机推荐

  1. java多线程之:SynchronousQueue队列

    SynchronousQueue是这样一种阻塞队列,其中每个 put 必须等待一个 take,反之亦然.同步队列没有任何内部容量,甚至连一个队列的容量都没有.      不能在同步队列上进行 peek ...

  2. /bin/rm: Argument list too long解決方法

    rm.cp.mv是unix下面常用到的檔案處理指令,當我們需要刪除大量的log檔案,如果檔案數太多就會出現此訊息[/bin/rm: Argument list too long]解決方式如下: 例如要 ...

  3. Win7+VS2010环境下CEGUI 0.8.4编译过程详解

    转载▼   1. 在http://cegui.org.uk/download 下载CEGUI源码包 cegui-0.8.4 以及CEGUI依赖库(Windows / Apple OS X only) ...

  4. XML序列化中含有List的情况,序列化到根节点下一层

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.X ...

  5. Oracle数据库概述

    Oracle是一种RDBMS(Relational Database Management System 关系型数据库管理系统),是Oracle公司的核心产品. 2009年4月,Oracle并购了Su ...

  6. js 触摸类库

    A javascript library for multi-touch gestures :// You can touch this  http://hammerjs.github.io     ...

  7. 实时监听输入框值变化的完美方案:oninput & onpropertychange

    实时监听输入框值变化的完美方案:oninput & onpropertychange: 网址:http://www.cnblogs.com/lhb25/archive/2012/11/30/o ...

  8. Nginx Google 扩展

    安装配置详见: https://github.com/cuber/ngx_http_google_filter_module/blob/master/README.zh-CN.md tenginx详见 ...

  9. elipse 调试 反射 invoke 子类

    真实案例: 调试一个接口,子类invoke的,结果断点断不到: 查找两个项目间的关联.依赖,无果. 问人吧,结果是配置文件没改成本机: #============================# # ...

  10. 使用async属性异步加载执行JavaScript

    HTML5让我兴奋的一个最大的原因是,它里面实现的新功能和新特征都是我们长久以来一直期待的.比如,我以前一直在使用placeholders,但以前必须要用JavaScript实现.而HTML5里给Ja ...