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
}
随机推荐
- GlassFish Server is a compliant implementation of the Java EE 7 platform
1.9 GlassFish Server Tools GlassFish Server is a compliant implementation of the Java EE 7 platform. ...
- java 将长度很长的字符串(巨大字符串超过4000字节)插入oracle的clob字段时会报错的解决方案
直接很长的字符串插入到clob字段中会报字符过长的异常,相信大家都会碰到这种情况 String sql = "insert into table(request_id,table_name, ...
- 转(JSONP处理跨域事件)
前言: 由于Sencha Touch 2这种开发模式的特性,基本决定了它原生的数据交互行为几乎只能通过AJAX来实现. 当然了,通过调用强大的PhoneGap插件然后打包,你可以实现100%的Soc ...
- Unity3D研究院编辑器之Editor的GUI的事件拦截
OnGUI是Unity上一个时代的UI系统,而现在运行时的UI系统已经被UGUI取代,但是Editor的UI还是在用老的这一套GUI系统.比如unity编辑器里的所有窗口,布局,按钮,拖动条.滚动等等 ...
- Page cache和Buffer cache[转1]
http://www.cnblogs.com/mydomain/archive/2013/02/24/2924707.html Page cache实际上是针对文件系统的,是文件的缓存,在文件层面上的 ...
- 从扩展方法到匿名方法再到LINQ
1.首先我们应该知道什么是扩展方法: 扩展方法使您能够向现有类型“添加”方法,而无需创建新的派生类型.重新编译或以其他方式修改原始类型. 扩展方法是一种特殊的静态方法,但可以像扩展类型上的实例方法一样 ...
- PHP使用libevent实现高性能httpServer
今天发现php也有一个libevent的扩展,安装后尝试下了一个webserver(httpserver), 发现性能还不错,逻辑很简单,每秒响应速度1800~4000次/s 代码如下 <?ph ...
- 关于spring 3.0.5的 <mvc:resources mapping="***" location="***">标签的使用
spring mvc 的<mvc;resources mapping="***" location="***">标签是在spring3.0.4出现的 ...
- 文件/文件夹比较工具 beyond compare 3.3.10
- Asianux的SSH登录问题,密码不正确解决
第一.ssh服务默认是关闭的,需要手动打开 [root@Asianux ~]# service sshd start 启动 [root@Asianux ~]#chkconfig sshd - ...