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. spring源码学习之【准备】cglib动态代理例子

    一:委托者 package com.yeepay.porxy.cglib.test; import java.util.HashMap; import java.util.Map; /** * 目标类 ...

  2. 论文笔记之:Multiple Object Recognition With Visual Attention

     Multiple Object Recognition With Visual Attention Google DeepMind  ICRL 2015 本文提出了一种基于 attention 的用 ...

  3. CentOS 6.5系统上安装SVN服务器端的方法及步骤

    VN其实就是Subversion,分为服务器端和客户端.之前在网上搜了很多方法,都有各种问题,经过自己搜集整理以及实际尝试,总算有个比较靠谱的方法.本文主要介绍CentOS 6.5系统上安装SVN服务 ...

  4. Asp.net MVC的actionlink到Areas里action

    <li>@Html.ActionLink("Home", "Index", "Home", new { area = " ...

  5. python_Day1_基础知识开篇

    一.python安装 1)windows上同时安装python2.0和python3.0配置 (1)在python官网下载windows版本python2.0和python3.0安装包 官网地址:ht ...

  6. 1.Nexus安装与配置

    1.Nexus下载下载地址:http://www.sonatype.org/nexus/go/下载后的文件:nexus-2.11.4-01-bundle.zip安装:直接解压到某个目录即可解压后,会有 ...

  7. python中时间日期格式化符号

    python中时间日期格式化符号: import time print(time.strftime('%Y%H%M%S', time.localtime())) 运行结果: 2016092308 %y ...

  8. html之input系列标签

    input属性太多,我这里仅列出几个我喜欢的吧. disabled:首次加载时禁用此元素 checked:首次加载时选中此元素 form:输入字段所属的一个或多个表单 hieght:定义input字段 ...

  9. ExtJs学习之Window

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  10. select跳转

    <select onchange="window.open(this.options[this.selectedIndex].value)"><option> ...