Unity学习笔记七 - Survival Shooter Tutorial
2016-04-25 20:41
393 查看
下面来看下EnemyHealth.cs脚本中的内容
void Awake ()
{
anim = GetComponent <Animator> ();
enemyAudio = GetComponent <AudioSource> ();
hitParticles = GetComponentInChildren <ParticleSystem> ();
capsuleCollider = GetComponent <CapsuleCollider> ();
currentHealth = startingHealth;
}
void Update ()
{
if(isSinking) //变量isSinking为true
{
transform.Translate (-Vector3.up * sinkSpeed * Time.deltaTime);
//使怪物的坐标逐渐下移,就是消失在地板下
}
}
public void TakeDamage (int amount, Vector3 hitPoint)
{
if(isDead) //如果isDead为true,就是已经置位,不执行后面的
return;
enemyAudio.Play ();
//播放enemy上的AudioSource组件中的音乐
currentHealth -= amount;//当前血量减少amount
hitParticles.transform.position = hitPoint;
//enemy上的hitParticles粒子效果位置设定在光束击中的点,根据前面的代码
hitParticles.Play(); //播放粒子效果
if(currentHealth <= 0)
//当前血量小于等于0,执行Death函数
{
Death ();
}
}
void Death ()
{
isDead = true;
//设置isDead = true,不用再死了
capsuleCollider.isTrigger = true;
//本enemy上的capsuleCollider IsTrigger 设置为true (1)
anim.SetTrigger ("Dead");
//触发本enemy的animator的组件
enemyAudio.clip = deathClip;
//设置本object的音乐片段为deathClip=死亡音乐片段
enemyAudio.Play ();
//播放音乐
}
public void StartSinking ()
{
GetComponent <NavMeshAgent> ().enabled = false;
//禁用NavMeshAgent组件,这是一个地图路径寻址导航的Navigation的执行单元,就是其可在Navigation制作和设定好的地图路线上寻路
GetComponent <Rigidbody> ().isKinematic = true;
//设置刚体组件的isKinematic为true
(2)
isSinking = true;
//把isSinking设为true,enemy可以通过transform.Translate强行下移了
ScoreManager.score += scoreValue;
//分数记录脚本ScoreManager的score,被声明为public static,分数记录脚本ScoreManager的score,被声明为public
static,作为类的不分实体而存在的变量,有独立的存储空间,不论类被new了几次,它的存储空间都不变
Destroy (gameObject, 2f);
//两秒钟后销毁此enemy
}
我在百度网盘上传的工程的一个bug,大象类怪物不会执行动画和下沉Animator设置有错
Prefabs->Hellephant中Animator组件的Controller选择为HellephantAOC,Animator override Controller,覆盖类,继承EnemyAnimatorController,原始是Hellephant的Move、Idle、Death覆盖的是zombunny的对应动画,而Animator中的转换关系和触发变量不变
附加TIPs:
1.我们如果注释掉(1),(2)两行,enemy还是继续下沉,说明 transform.Translate (-Vector3.up * sinkSpeed * Time.deltaTime);使武器强行移动
2.如果我们注释掉 transform.Translate (-Vector3.up * sinkSpeed * Time.deltaTime);,e
af5d
nemy不下沉,只是2秒后会消失
void Awake ()
{
anim = GetComponent <Animator> ();
enemyAudio = GetComponent <AudioSource> ();
hitParticles = GetComponentInChildren <ParticleSystem> ();
capsuleCollider = GetComponent <CapsuleCollider> ();
currentHealth = startingHealth;
}
void Update ()
{
if(isSinking) //变量isSinking为true
{
transform.Translate (-Vector3.up * sinkSpeed * Time.deltaTime);
//使怪物的坐标逐渐下移,就是消失在地板下
}
}
public void TakeDamage (int amount, Vector3 hitPoint)
{
if(isDead) //如果isDead为true,就是已经置位,不执行后面的
return;
enemyAudio.Play ();
//播放enemy上的AudioSource组件中的音乐
currentHealth -= amount;//当前血量减少amount
hitParticles.transform.position = hitPoint;
//enemy上的hitParticles粒子效果位置设定在光束击中的点,根据前面的代码
hitParticles.Play(); //播放粒子效果
if(currentHealth <= 0)
//当前血量小于等于0,执行Death函数
{
Death ();
}
}
void Death ()
{
isDead = true;
//设置isDead = true,不用再死了
capsuleCollider.isTrigger = true;
//本enemy上的capsuleCollider IsTrigger 设置为true (1)
anim.SetTrigger ("Dead");
//触发本enemy的animator的组件
enemyAudio.clip = deathClip;
//设置本object的音乐片段为deathClip=死亡音乐片段
enemyAudio.Play ();
//播放音乐
}
public void StartSinking ()
{
GetComponent <NavMeshAgent> ().enabled = false;
//禁用NavMeshAgent组件,这是一个地图路径寻址导航的Navigation的执行单元,就是其可在Navigation制作和设定好的地图路线上寻路
GetComponent <Rigidbody> ().isKinematic = true;
//设置刚体组件的isKinematic为true
(2)
isSinking = true;
//把isSinking设为true,enemy可以通过transform.Translate强行下移了
ScoreManager.score += scoreValue;
//分数记录脚本ScoreManager的score,被声明为public static,分数记录脚本ScoreManager的score,被声明为public
static,作为类的不分实体而存在的变量,有独立的存储空间,不论类被new了几次,它的存储空间都不变
Destroy (gameObject, 2f);
//两秒钟后销毁此enemy
}
我在百度网盘上传的工程的一个bug,大象类怪物不会执行动画和下沉Animator设置有错
Prefabs->Hellephant中Animator组件的Controller选择为HellephantAOC,Animator override Controller,覆盖类,继承EnemyAnimatorController,原始是Hellephant的Move、Idle、Death覆盖的是zombunny的对应动画,而Animator中的转换关系和触发变量不变
附加TIPs:
1.我们如果注释掉(1),(2)两行,enemy还是继续下沉,说明 transform.Translate (-Vector3.up * sinkSpeed * Time.deltaTime);使武器强行移动
2.如果我们注释掉 transform.Translate (-Vector3.up * sinkSpeed * Time.deltaTime);,e
af5d
nemy不下沉,只是2秒后会消失
相关文章推荐
- 我是运营,我没有假期
- 肯特·贝克:改变人生的代码整理魔法
- 你应该学习哪种编程语言?
- 每个 Linux 游戏玩家都绝不想要的恼人体验
- 在 Fedora 上使用 Steam play 和 Proton 来玩 Windows 游戏
- [转]我们需要一种其他人能使用的编程语言
- Steam 让我们在 Linux 上玩 Windows 的游戏更加容易
- 如何使用 Steam Play 在 Linux 上玩仅限 Windows 的游戏
- 新一代iPad适配应用之游戏篇
- DB2编程序技巧(1)
- DB2编程序技巧 (四)
- 女人VS编程_国庆快乐
- DB2编程序技巧 (六)
- DB2编程序技巧 (三)
- DB2编程序技巧 (九)
- DB2编程序技巧 (七)
- DB2编程序小小技巧
- DB2编程序技巧 (五)
- VB实现的《QQ美女找茬游戏》作弊器实例
- DB2编程序技巧 (一)