调用UI游戏时无法正常运行?

时间:2018-10-07 20:42:00

标签: unity3d

所以我有一个隐形游戏的敌人防护脚本,如果发现玩家过度展示游戏情况,我会ed缩。 (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上的图像仅显示一次,游戏结束功能不再被调用。玩家第一次失去关卡时才被召唤,之后您就可以进入敌人的视野并且什么也不会发生。

0 个答案:

没有答案