//this function handles collisions with players void OnTriggerStay(Collider col) { if (active && capturableFloor && resMgr.isActive() && col.gameObject.tag == "Player") { Player player = col.gameObject.GetComponent <Player>(); //if we already own this tile, restore its capture resistance 'HP' to full power. if (player.playerID == ownerID) { timeStayed = 0.0f; captureTimeThreshold = fullResistance; return; } //update the time stayed inside the tile timeStayed += Time.deltaTime; //if the capture time threshhold has been met, capture this tile if (timeStayed > captureTimeThreshold) { changeOwner(player); } } }
void OnTriggerStay(Collider col) { //if we can't capture this hub, don't bother processing further. if (captureLocked || uncapturable || !resMgr.isActive()) { return; } if (col.GetComponent <Collider>().gameObject.tag == "Player") { //grab the player Player player = col.gameObject.GetComponent <Player>(); //safety check, and if we already own this tile, don't waste any more time if (player == null || player.playerID == ownerID) { return; } //update the time stayed inside the hub timeStayed[player.playerID - 1] += Time.deltaTime; //stop here if the player hasn't been here long enough to perform a capture. if (timeStayed[player.playerID - 1] < captureTime) { return; } //immediately lock this hub while capturing is being processed, to avoid problems related by the async calling of this function. captureLocked = true; Debug.Log("HUB ID " + hubID + " Captured By Player " + (player.playerID)); //zero timestayed for all players - so no one already in the hub can quickly recapture for (int i = 0; i < timeStayed.Length; i++) { timeStayed[i] = 0.0f; } //swap owners int oldOwnerID = ownerID; ownerID = player.playerID; //update the player's stats for (int i = 0; i < pls.Length; i++) { if (pls[i].playerID == ownerID) { pls[i].stats.numHubsOwned++; } else if (pls[i].playerID == oldOwnerID) { pls[i].stats.numHubsOwned--; } } //perform a UI update if (ownerID > -1) { pls[ownerID - 1].hud.updateTilesOwned(); if (oldOwnerID >= 0) { pls[oldOwnerID - 1].hud.updateTilesOwned(); } } resMgr.checkWinPotential(); //unlock capturing captureLocked = false; } }