定义
定义一个游戏对象数组,存储查找到的对象
//场景中剩余子弹袋数
public Object[] left;
实现
数组长度为0,说明场景中已经没有这种游戏对象了
left = GameObject.FindGameObjectsWithTag("bulletget");
Debug.Log(left.Length);
//如果生命值为0,或者场景中没有子弹,显示游戏结束字样,并销毁主角
if (currentHealth==0||(curBulletCount==0&& left.Length == 0))
智能提示
else if(curBulletCount==0 && currentHealth!=0&& left.Length != 0)
{
tipsframe.SetActive(true);
tips.text = "Tips:\n没有子弹了,快去拾取子弹吧!";
}
else if (curBulletCount == 0 && left.Length == 0 && enemyleft != 0)
{
tipsframe.SetActive(true);
tips.text = "Tips:\n你已经用完了本关提供的所有子弹!";
}
效果

附完整教程:
原博地址
https://blog.csdn.net/weixin_43673589
浙公网安备 33010602011771号