【发布时间】:2020-10-09 03:38:54
【问题描述】:
制作一个滚动游戏并将其分解成更小的部分,直到我解决了新添加的问题,然后将其添加到游戏中。我想出了如何为玩家创建一个健康条,这样当他被敌人击中时,它会显示健康条的水平正在减少。我似乎无法为敌人的老板做相反的事情。现在我有一个名为 healthbar 的玩家进度条设置为 100%,每次玩家被击中时都会减少 10。我还有一个 Boss 的进度条,叫做 bosshealth,它也设置为 100%,每次被击中时也会减少 10。现在当 Boss 用他的激光击中玩家时,玩家会受到伤害,但当玩家射击 Boss 时,他不会受到任何伤害。
void HitorMiss()
{
if(Player.Bounds.IntersectsWith(powerarmour.Bounds) || Player.Bounds.IntersectsWith(e1laser.Bounds))
{
if (healthbar.Value <= 0)
{
healthbar.Value = 100;
}
else if (healthbar.Value == 0)
Dead();
else
healthbar.Value -= 10;
}
else if(powerarmour.Bounds.IntersectsWith(shoot.Bounds))
{
if (bosshealth.Value <= 0)
{
bosshealth.Value = 100;
}
else if (bosshealth.Value == 0)
{
//code to make boss explode and then disappear
}
else
bosshealth.Value -= 10;
}
}
【问题讨论】:
-
您是否调试过它是否进入了 else if(powerarmour.Bounds.IntersectsWith(shoot.Bounds)) 块?也许碰撞并不像预期的那样。另外,您是否使用 Unity 或某些库来执行此操作?请标记它。
标签: c#