// guard checks if a rock dropped next to them Vector3 CheckForRock() { GameObject[] rocks = GameObject.FindGameObjectsWithTag("Rock"); foreach (GameObject rock in rocks) { // gets the rock alert component RockHitGroundAlert tempRock = rock.transform.GetChild(0).GetChild(0).gameObject.GetComponent <RockHitGroundAlert>(); // if the rock has hit the ground check whether the distance is close enough for the guard to alert other guards if (tempRock.rockHitGround) { //Debug.Log(Vector3.Distance(transform.position, tempRock.transform.position)); if (Vector3.Distance(transform.position, tempRock.transform.position) < 30) { return(tempRock.transform.position); } } } return(new Vector3(0f, 0f, 0f)); }
// function is subscribed to rock event for when rock hits ground, checks which rock hit the ground void CheckForRock() { if (!PhotonNetwork.IsMasterClient) { return; } GameObject[] rocks = GameObject.FindGameObjectsWithTag("Rock"); foreach (GameObject rock in rocks) { // gets the rock alert component RockHitGroundAlert tempRock = rock.transform.GetChild(0).GetChild(0).gameObject.GetComponent <RockHitGroundAlert>(); // if the rock has hit the ground check whether the distance is close enough for the guard to alert other guards if (tempRock.rockHitGround) { if (Vector3.Distance(transform.position, tempRock.transform.position) < 30) { SetGuardsToAlertedItem(tempRock.transform.position); // checks which player threw the rock and completes achievement GameObject[] players = GameObject.FindGameObjectsWithTag("Player"); foreach (var player in players) { if (player.GetComponent <PhotonView>().Owner == rock.GetComponent <PhotonView>().Controller) { if (tempRock.GetComponent <Unachievable>() == null) { player.GetComponent <Achievements>()?.UseNatureCompleted(); } return; } } return; } } } }