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. 详解LUA开发工具及其环境配置

    LUA开发工具及其环境配置是本文要介绍的内容,主要是来了解并学习lua开发工具的使用和环境的配置,第一次接触LUA的话,就跟本人一起学习吧.看我能不能忽悠到你. LUA是语言,那么一定有编写的工具.第 ...

  2. Firefox-常用扩展

    抓包: HttpFox,相比 Firebug 在页面跳转或刷新时依旧保持原有数据 常用User-Agent模拟: User Agent Switcher 更改请求头: ModifyHeaders 更改 ...

  3. Hive 安装配置记录

    http://yymmiinngg.iteye.com/blog/708230 export HADOOP_HOME_WARN_SUPPRESS=1 export JAVA_HOME=/home/ha ...

  4. UserDefault的使用,保存小数据到本地-iOS

    //保持到本地数据 NSArray *array=@[@"234",@"sdfe"]; NSUserDefaults *userDefault=[NSUserD ...

  5. OkHttpUtils

    对okhttp的封装类,okhttp见:https://github.com/square/okhttp.目前对应okhttp版本3.3.1. 用法: Android Studio compile ' ...

  6. es6新特性

    变量-------------------------- let, const:必须直接给一个变量赋值.注意,对象的属性或数组成员还是可以改变的. const MY_OBJECT = {some: 1 ...

  7. Win7系统上配置使用Intellij Idea 13的SVN插件

    Win7系统上配置使用Intellij Idea 13的SVN插件 http://blog.csdn.net/jeepxiaozi/article/details/39856081

  8. 日期转换工具类 CommUtil.java

    package com.util; import java.text.ParseException; import java.text.SimpleDateFormat; import java.ut ...

  9. 在阿里云 centos 6.3上面安装php5.2(转)

    由于php程序使用了Zend Optimizer,只能使用php5.2, yum 上的php 是5.3的版本,只能重新安装php:安装步骤如下: 先卸载 php5.3的相关东西: yum remove ...

  10. 在VS2008环境下的C++异常处理

    在写DAServer的过程中,一直在重视报文逻辑处理,却没有认认真真地去思考异常处理的问题.曾经我发现我在所有的报文处理函数中均没有考虑报文长度的问题,让我内心不由地捏了一把冷汗.我在新增的故障录波及 ...