消灭Boss
1.添加Boss生命健康管理
在BossTankController.cs中添加参数
[Header("生命健康参数")]
public int health = 5; //Boss生命值
public GameObject explosion; //死亡特效
private bool isDefeated; //是否被击败
在TakeHit()函数中,销毁地雷之后,添加受伤减少生命值逻辑
//受伤减少生命值
health--;
if(health <= 0)
{
isDefeated = true;
}
在case bossState.hurt:
中,在释放地雷计数器清零mineCounter = 0;
之后,添加判断Boss是否被击败
//Boss被击败,隐藏boss并播放特效
if(isDefeated)
{
theBoss.gameObject.SetActive(false);
Instantiate(explosion, theBoss.position, theBoss.rotation);
}
在Unity中,绑定死亡特效
2.添加状态
新增Boss状态ended
//状态枚举
public enum bossState
{
shooting,
hurt,
moving,
ended
}
在case bossState.hurt:
中,Boss被击败后,改变状态为ended
//Boss被击败,隐藏boss并播放特效
if(isDefeated)
{
theBoss.gameObject.SetActive(false);
Instantiate(explosion, theBoss.position, theBoss.rotation);
//切换为结束状态
currentState = bossState.ended;
}
3.Boss受伤后攻击状态改变
新增参数
public float shotSpeedup; //射击速度
public float mineSpeedup; //埋雷速度
在Unity中设置初始值1.2
在TakeHit()函数中,判断health<=0
之后加入else,改变射击速度和埋雷速度
//受伤减少生命值
health--;
if(health <= 0)
{
isDefeated = true;
}else
{
timeBetweenShot /= shotSpeedup;
timeBetweenMines /= mineSpeedup;
}
4.击败Boss后,显示隐藏的平台
新建空节点,命名为PlatformHolder,加入OneWayPlatform,设置隐藏
添加参数
public GameObject winPlatForm; //胜利平台
Unity中,绑定PlatformHolder节点到winPlatForm
在case bossState.hurt:
中,判断被击败后,切换结束状态前,添加显示胜利平台
//Boss被击败,隐藏boss并播放特效
if(isDefeated)
{
theBoss.gameObject.SetActive(false);
Instantiate(explosion, theBoss.position, theBoss.rotation);
//显示胜利平台
winPlatForm.SetActive(true);
//切换为结束状态
currentState = bossState.ended;
}
5.优化游戏(Player踩在子弹上会消灭子弹)
新加Layers层级Stompbox和Bullets
设置Player下的Stompbox的Layer层级为Stompbox
子弹预制体TankBossBullet中,将Layer层级设置为Bullets
菜单栏->Edit->Project Setting,选中Physics 2D,取消Stompbox和Bullets的交集点