unity3d - 调用 UI 游戏无法正常运行?
问题描述
所以我有一个用于隐身游戏的敌人守卫脚本,如果发现玩家显示游戏结束状态,则会进行检查。(游戏在 UI 上的文本)。
void Start()
{
if(player == null)
{
GameObject.FindGameObjectWithTag("Player");
}
viewAngle = spotlight.spotAngle;
originalSpotlighyColour = spotlight.color;
Vector3[] waypoints = new Vector3[pathHolder.childCount];
for (int i = 0; i < waypoints.Length; i++)
{
waypoints [i] = pathHolder.GetChild (i).position;
waypoints [i] = new Vector3 (waypoints [i].x, transform.position.y, waypoints [i].z);
}
StartCoroutine (FollowPath (waypoints));
}
void Update()
{
if (CanSeePlayer())
{
playerVisibleTimer += Time.deltaTime;
// spotlight.color = Color.red;
} else
{
playerVisibleTimer -= Time.deltaTime;
// spotlight.color = originalSpotlighyColour;
}
playerVisibleTimer = Mathf.Clamp(playerVisibleTimer, 0, timeToSpotPlayer);
spotlight.color = Color.Lerp(originalSpotlighyColour, Color.red, playerVisibleTimer / timeToSpotPlayer);
if(playerVisibleTimer>= timeToSpotPlayer)
{
if (OnGuardHasSpottedPlayer != null)
{
OnGuardHasSpottedPlayer();
StopAllCoroutines();
Seek();
GameUI.gameIsOver = true;
}
}
}
条件很简单:
如果看到玩家,则出现游戏结束图像,玩家将按空格键重新启动阶段。但是 UI 上的图像只显示一次,游戏结束功能不会再次调用。只是在玩家失去关卡时第一次调用,之后你可以进入敌人的视野,什么都不会发生。
解决方案
推荐阅读
- sql - SQL 中的块平均值
- java - 为什么我不能在 Java 的数组中分配 Arrays.sort() 的输出?
- java - 可嵌入类字段上的@Column(name="alternative") 使实体类中的@AttributeOverrides 没有必要?
- r - 使用 gt 包创建一个函数以在 R 中针对已批准和未批准的客户显示勾选和交叉?
- java - 这行中的 {0} double [] array = new double[] {0} 在 java 中做了什么?
- ios - 执行 UI 块时引发 React Native 异常:一个视图一次只能与一个视图控制器关联
- strapi - Strapi:谷歌提供商问题
- javascript - 使用 fetch api 和 express.js 后,我的按钮无法正常工作
- python - 释放所有键时如何触发pynput的GlobalHotkeys?
- ansible - Ansible - 如何在远程服务器中使用查找