// Update is called once per frame void Update() { timeLeft -= Time.deltaTime; string minSec = string.Format("{0}:{1:00}", (int)timeLeft / 60, (int)timeLeft % 60); currentTimerText.text = minSec; if (timeLeft < 0 && !gameEnded) { gameEnded = !gameEnded; GameObject castleMultiplayer = GameObject.Find("Castle (multiplayer)(Clone)"); // fetch castle object CastleMultiplayer castleController = castleMultiplayer.GetComponent <CastleMultiplayer>(); float masterStrength = castleController.masterCastleStrength; float clientStrength = castleController.clientCastleStrength; // compare strengths to determine winner if (masterStrength > clientStrength) { castleController.EndBattle(true); } else { castleController.EndBattle(false); } } }
//destroy this unit public void Die() { string ownerTag = local ? masterClientCastle : clientCastle; CastleMultiplayer owner = GameObject.FindGameObjectWithTag(ownerTag).transform.parent.GetComponent <CastleMultiplayer>(); owner.DestroyUnit(gameObject, unitType, dieEffect); }
//check if the battle has ended bool BattleEnded() { GameObject localCastle = CastleMultiplayer.LocalCastle; CastleMultiplayer castle = localCastle.GetComponent <CastleMultiplayer>(); return(castle.battleEnded); }
//notify the player when he kills a unit void UnitKilled(string tag, string type) { if (tag == clientUnit) { CastleMultiplayer localCastle = CastleMultiplayer.LocalCastle.GetComponent <CastleMultiplayer>(); localCastle.masterKills++; KillNotification(type); } else { clientKills++; photonView.RPC("ClientKillNotification", PhotonTargets.Others, type); } }
//initialize as soon as the castle has reached the game scene public void Initialize(GameUI gameUI, CastleMultiplayer castle) { box = gameUI.selectionBox; canvas = gameUI.selectionCanvas; boxTransform = box.GetComponent <RectTransform>(); boxTransform.pivot = Vector2.one * 0.5f; boxTransform.anchorMin = Vector2.one * 0.5f; boxTransform.anchorMax = Vector2.one * 0.5f; box.gameObject.SetActive(false); bool masterCastle = castle.castleParts[0].castlePart.CompareTag(castle.masterClientCastle); targetTag = masterCastle ? castle.masterClientUnit : castle.clientUnit; }
void Start() { //find gameobjects switchSelectionModeButton = GameObject.Find("Switch selection mode button"); buttons = GameObject.Find("Buttons"); GameObject local = CastleMultiplayer.LocalCastle; if (local != null) { localCastle = local.GetComponent <CastleMultiplayer>(); } gameInitializer = GameObject.FindObjectOfType <InitializeGame>(); gameUI = GameObject.FindObjectOfType <GameUI>(); }
void AttackCastle() { //if there's no enemy castle, try to find one if (enemyCastle == null) { GameObject targetCastle = GetTarget(castleAttackTag); if (targetCastle != null) { enemyCastle = targetCastle.transform; } return; } //update the arrow force for the archers to use if (archer) { UpdateArrowForce(enemyCastle.position); } //attack the castle if close enough if (Vector3.Distance(enemyCastle.position, transform.position) < castleStoppingDistance) { CastleMultiplayer castle = enemyCastle.parent.GetComponent <CastleMultiplayer>(); castle.AttackCastle(enemyCastle.gameObject, damage); LookAt(enemyCastle); CheckState(true); } else { agent.destination = enemyCastle.position; CheckState(false); } }