// Update is called once per frame void Update() { bool oneVisible = false; //At least one player is visible foreach (GameObject g in playersInVision) { if (!g.GetComponent <PlayerController>().hidden) { oneVisible = true; //Player not hidden if (!hasDetected) { hasDetected = true; spottedTime = Time.time + findTime; } } } if (!oneVisible) { //If none is visible anymore, don't spot hasDetected = false; } if (hasDetected && Time.time > spottedTime) { hasDetected = false; //Debug.Log("Spotted"); foreach (GameObject g in playersInVision) { if (!g.GetComponent <PlayerController>().hidden) { //Tell main camera to do animation GameObject mainCamera = GameObject.FindGameObjectWithTag("MainCamera"); if (mainCamera) { MainCameraController mainCameraController = mainCamera.GetComponent <MainCameraController>(); if (mainCameraController) { mainCameraController.SpotPlayer(g.gameObject); } } break; } } } }