internal IEnumerator EnemySpecialActions(string Pass) { if (System.String.Equals(Pass, "Healing")) //heal 1 damage to healer enemy type every 3 seconds { if (CurrentEnemyID == EnemyID.Regenerator) { yield return(new WaitForSeconds(3)); //spawn interval CurrentHP++; GameManager.DisplayValue(1, transform.position); StartCoroutine(EnemySpecialActions("Healing")); } else if (CurrentEnemyID == EnemyID.Support) { yield return(new WaitForSeconds(3)); if (Ally.GetComponent <EnemyFunction>().CurrentHP + 2 <= Ally.GetComponent <EnemyFunction>().MaxHP) { Ally.GetComponent <EnemyFunction>().CurrentHP += 2; } GameManager.DisplayValue(1, Ally.transform.position); StartCoroutine(EnemySpecialActions("Healing")); } } }
public void selectCharacters() { //turn selection mode on/off selectionMode = !selectionMode; if (selectionMode) { //set cursor and button color to show the player selection mode is active selectButton.GetComponent <Image>().color = Color.red; Cursor.SetCursor(cursorTexture1, Vector2.zero, CursorMode.Auto); if (GameObject.Find("Mobile multiplayer")) { if (MobileMultiplayer.deployMode) { GameObject.Find("Mobile multiplayer").GetComponent <MobileMultiplayer>().toggleDeployMode(); } MobileMultiplayer.camEnabled = false; } } else { //show the player selection mode is not active selectButton.GetComponent <Image>().color = Color.white; Cursor.SetCursor(cursorTexture, Vector2.zero, CursorMode.Auto); //set target object false and deselect all units foreach (GameObject Ally in allies) { if (Ally != null) { Ally.GetComponent <CharacterMultiplayer>().selected = false; } } target.SetActive(false); if (GameObject.Find("Mobile multiplayer")) { MobileMultiplayer.camEnabled = true; } } }
void OnGUI() { //check if rectangle should be visible if (visible) { // Find the corner of the box Vector2 origin; origin.x = Mathf.Min(mouseDownPos.x, mouseLastPos.x); // GUI and mouse coordinates are the opposite way around. origin.y = Mathf.Max(mouseDownPos.y, mouseLastPos.y); origin.y = Screen.height - origin.y; //Compute size of box Vector2 size = mouseDownPos - mouseLastPos; size.x = Mathf.Abs(size.x); size.y = Mathf.Abs(size.y); // Draw the GUI box Rect rect = new Rect(origin.x, origin.y, size.x, size.y); GUI.Box(rect, "", rectangleStyle); foreach (GameObject Ally in allies) { if (Ally != null) { Vector3 pos = Camera.main.WorldToScreenPoint(Ally.transform.position); pos.y = Screen.height - pos.y; //foreach selectable character check its position and if it is within GUI rectangle, set selected to true if (rect.Contains(pos)) { Ally.GetComponent <CharacterMultiplayer>().selected = true; } } } } }
void Update() { //make sure this is the local player and there are 2 castles in the scene if (!isLocalPlayer || FindObjectsOfType <GameManagerMultiplayer>().Length != 2) { return; } if (bombProgress < 1) { //when bomb is loading, set red color and disable button bombProgress += Time.deltaTime * bombLoadingSpeed; bombLoadingBar.GetComponent <Image>().color = Color.red; bombButton.GetComponent <Button>().enabled = false; } else { //if bomb is done, set a blue color and enable the bomb button bombProgress = 1; bombLoadingBar.GetComponent <Image>().color = new Color(0, 1, 1, 1); bombButton.GetComponent <Button>().enabled = true; } //set fillamount to the bomb progress bombLoadingBar.GetComponent <Image>().fillAmount = bombProgress; //ray from main camera RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { //check if left mouse button gets pressed if (Input.GetMouseButtonDown(0)) { //if you didn't click on UI and you have not enought gold, display a warning if (gold < troops[selectedUnit].troopCosts && !EventSystem.current.IsPointerOverGameObject()) { StartCoroutine(GoldWarning()); } //check if you hit any collider when clicking (just to prevent errors) if (hit.collider != null) { //if you click battle ground, if click doesn't hit any UI, if space is not down and if you have enough gold: if (hit.collider.gameObject.CompareTag("Battle ground") && !selectionMode && !isPlacingBomb && !EventSystem.current.IsPointerOverGameObject() && gold >= troops[selectedUnit].troopCosts && (!GameObject.Find("Mobile multiplayer") || (GameObject.Find("Mobile multiplayer") && MobileMultiplayer.deployMode)) && (!ownHalfOnly || (ownHalfOnly && ((transform.position.x < 0 && hit.point.x < -2) || (transform.position.x > 0 && hit.point.x > 2))))) { SpawnUnit(hit.point, null, false, false); //get the amount of gold needed to spawn this unit gold -= troops[selectedUnit].troopCosts; } //if the other side of the battle ground was clicked, and its not allowed, show a warning else if (hit.collider.gameObject.CompareTag("Battle ground") && !selectionMode && !isPlacingBomb && !EventSystem.current.IsPointerOverGameObject() && gold >= troops[selectedUnit].troopCosts && (!GameObject.Find("Mobile multiplayer") || (GameObject.Find("Mobile multiplayer") && MobileMultiplayer.deployMode)) && ownHalfOnly && transform.position.x <0 && hit.point.x> -2) { StartCoroutine(deployWrongSideWarning(2)); } //if the other side of the battle ground was clicked, and its not allowed, show a warning else if (hit.collider.gameObject.CompareTag("Battle ground") && !selectionMode && !isPlacingBomb && !EventSystem.current.IsPointerOverGameObject() && gold >= troops[selectedUnit].troopCosts && (!GameObject.Find("Mobile multiplayer") || (GameObject.Find("Mobile multiplayer") && MobileMultiplayer.deployMode)) && ownHalfOnly && transform.position.x > 0 && hit.point.x < 2) { StartCoroutine(deployWrongSideWarning(1)); } //if you are placing a bomb and click... if (isPlacingBomb && !EventSystem.current.IsPointerOverGameObject()) { //instantiate explosion if (host) { GameObject explosion = Instantiate(bombExplosion, hit.point, Quaternion.identity); NetworkServer.Spawn(explosion); foreach (GameObject enemy in GameObject.FindGameObjectsWithTag("Player 2 unit")) { if (enemy != null && Vector3.Distance(enemy.transform.position, hit.point) <= BombRange / 2) { //kill enemy if its within the bombrange enemy.GetComponent <CharacterMultiplayer>().lives = 0; } } } else { //use a command if this is not the host CmdSpawnExplosion(hit.point); } //reset bomb progress bombProgress = 0; isPlacingBomb = false; bombRange.SetActive(false); } else if (hit.collider.gameObject.CompareTag("Battle ground") && isPlacingBomb && EventSystem.current.IsPointerOverGameObject()) { //if you place a bomb and click any UI element, continue but don't reset bomb progress isPlacingBomb = false; bombRange.SetActive(false); } } } } if (hit.collider != null && isPlacingBomb && !EventSystem.current.IsPointerOverGameObject()) { //show the bomb range at mouse position using a spot light bombRange.transform.position = new Vector3(hit.point.x, 75, hit.point.z); //adjust spotangle to correspond to bomb range bombRange.GetComponent <Light>().spotAngle = BombRange; bombRange.SetActive(true); } //if space is down too set the position where you first clicked if (Input.GetMouseButtonDown(0) && selectionMode && !isPlacingBomb && (!GameObject.Find("Mobile multiplayer") || (GameObject.Find("Mobile multiplayer") && !MobileMultiplayer.selectionModeMove))) { mouseDownPos = Input.mousePosition; isDown = true; visible = true; } // Continue tracking mouse position until mouse button is up if (isDown) { mouseLastPos = Input.mousePosition; //if you release mouse button, remove rectangle and stop tracking if (Input.GetMouseButtonUp(0)) { isDown = false; visible = false; } } //get all ally units according to the team if (host) { allies = GameObject.FindGameObjectsWithTag("Player 1 unit"); } else { allies = GameObject.FindGameObjectsWithTag("Player 2 unit"); } //if player presses d, deselect all characters if (Input.GetKey("x")) { foreach (GameObject Ally in allies) { if (Ally != null) { Ally.GetComponent <CharacterMultiplayer>().selected = false; } } } //start selection mode when player presses spacebar if (Input.GetKeyDown("space")) { selectCharacters(); } //update gold display goldBar.fillAmount = (gold / maxGold); goldText.text = "" + gold; //color buttons grey if the unit is not deployable yet for (int i = 0; i < troops.Count; i++) { if (troops[i].troopCosts <= gold) { troops[i].button.gameObject.GetComponent <Image>().color = Color.white; } else { troops[i].button.gameObject.GetComponent <Image>().color = new Color(0.7f, 0.7f, 0.7f, 1); } } }