public void Rpc_dealDamage(GameObject attackingUnit, GameObject enemy) { Debug.Log(enemy.name); if (enemy.GetComponent <BasicAnt> () && attackingUnit.GetComponent <BasicAnt> ()) { BasicAnt enemyAnt = enemy.GetComponent <BasicAnt> (); UnitIdentity enemyAntIdentity = enemy.GetComponent <UnitIdentity> (); BasicAnt myAnt = attackingUnit.GetComponent <BasicAnt> (); UnitIdentity myAntIdentity = attackingUnit.GetComponent <UnitIdentity> (); if (myAntIdentity.id == enemyAntIdentity.id) { return; } enemyAnt.health -= Random.Range(0, myAnt.damage); myAnt.health -= Random.Range(0, enemyAnt.damage); } if (enemy.GetComponent <Anthill> () && attackingUnit.GetComponent <BasicAnt> ()) { Anthill enemyAntHill = enemy.GetComponent <Anthill> (); BasicAnt myAnt = attackingUnit.GetComponent <BasicAnt> (); UnitIdentity antHillIdentity = enemy.GetComponent <UnitIdentity> (); UnitIdentity myAntIdentity = attackingUnit.GetComponent <UnitIdentity> (); Debug.Log("shit works up to here1"); if (myAntIdentity.id == antHillIdentity.id) { return; } Debug.Log("shit works up to here2"); enemyAntHill.health -= Random.Range(0, myAnt.damage); Debug.Log("shit works up to here3"); } else { Debug.Log(enemy.name); Debug.Log(attackingUnit.name); } }
void Update() { if (!EventSystem.current.IsPointerOverGameObject()) { // Click somewhere in the Game View. if (Input.GetMouseButtonDown(0)) { // Get the initial click position of the mouse. No need to convert to GUI space // since we are using the lower left as anchor and pivot. initialClickPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y); // The anchor is set to the same place. selectionBox.anchoredPosition = initialClickPosition; } // While we are dragging. if (Input.GetMouseButton(0)) { // Store the current mouse position in screen space. Vector2 currentMousePosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y); // How far have we moved the mouse? Vector2 difference = currentMousePosition - initialClickPosition; // Copy the initial click position to a new variable. Using the original variable will cause // the anchor to move around to wherever the current mouse position is, // which isn't desirable. Vector2 startPoint = initialClickPosition; //Debug.Log ("Width: " + difference.x + " Height: " + difference.y); // The following code accounts for dragging in various directions. if (difference.x < 0) { startPoint.x = currentMousePosition.x; difference.x = -difference.x; } if (difference.y < 0) { startPoint.y = currentMousePosition.y; difference.y = -difference.y; } // Set the anchor, width and height every frame. selectionBox.transform.position = startPoint; selectionBox.sizeDelta = difference; } } // After we release the mouse button. if (Input.GetMouseButtonUp(0)) { Rect rect = new Rect(selectionBox.anchoredPosition, selectionBox.sizeDelta); foreach (GameObject unit in WorldHandler.countUnitsAsArray()) { if (rect.Contains((Vector2)Camera.main.WorldToScreenPoint(unit.transform.position))) { /*if (!WorldHandler.isShiftDown ()) { * WorldHandler.deselectUnits (); * WorldHandler.deselectAntHill (); * WorldHandler.hideAnthillInfo (); * }*/ GameObject indicator = unit.transform.FindChild("Indicator").gameObject; if (unit.GetComponent <BasicAnt> () != null) // changed with addition of beatle { BasicAnt unitScript = unit.GetComponent <BasicAnt> (); indicator.SetActive(!indicator.activeSelf); unitScript.isUnitSelected = indicator.activeSelf; if (unitScript.isUnitSelected) { WorldHandler.PlayUnitBattleSound(); } if (unitScript.isUnitSelected) { WorldHandler.unitsSelected.Add(unit); } else { WorldHandler.unitsSelected.Remove(unit); } } if (unit.GetComponent <Beatle> () != null) // changed with addition of beatle. { Beatle unitScript = unit.GetComponent <Beatle> (); indicator.SetActive(!indicator.activeSelf); unitScript.isUnitSelected = indicator.activeSelf; if (unitScript.isUnitSelected) { WorldHandler.PlayUnitBattleSound(); } if (unitScript.isUnitSelected) { WorldHandler.unitsSelected.Add(unit); } else { WorldHandler.unitsSelected.Remove(unit); } } } } // Reset initialClickPosition = Vector2.zero; selectionBox.anchoredPosition = Vector2.zero; selectionBox.sizeDelta = Vector2.zero; } }