public override void Use(HexCell target = null) { HexUnit targetUnit = target.hexUnits.Find(C => C.HexUnitType == HexUnit.UnitType.COMBAT); if (targetUnit) { targetUnit.GetComponent <Unit>().HitPoints -= (config as DamageUnitConfig).GetDamage(); targetUnit.GetComponent <Unit>().UpdateUI(); if (targetUnit.GetComponent <Unit>().HitPoints <= 0) { targetUnit.DieAnimationAndRemove(); } } PlayParticleEffect(); PlayAbilitySound(); PlayAnimation(); }
IEnumerator TravelPath() { Vector3 lookTowards = new Vector3(0, 0, 0); if (!currentTravelLocation) { currentTravelLocation = pathToTravel[0]; } int currentColumn = currentTravelLocation.ColumnIndex; int nextColumn; if (Location.IsVisible == true || HexVision.HasVision) { Vector3 a, b, c = pathToTravel[0].Position; yield return(LookAt(pathToTravel[1].Position)); animator.SetBool("Walking", true); HexVision.ClearCells(); float t = Time.deltaTime * travelSpeed; for (int i = 1; i < pathToTravel.Count; i++) { currentTravelLocation = pathToTravel[i]; a = c; b = pathToTravel[i - 1].Position; nextColumn = currentTravelLocation.ColumnIndex; if (currentColumn != nextColumn) { if (nextColumn < currentColumn - 1) { a.x -= HexMetrics.innerDiameter * HexMetrics.wrapSize; b.x -= HexMetrics.innerDiameter * HexMetrics.wrapSize; } else if (nextColumn > currentColumn + 1) { a.x += HexMetrics.innerDiameter * HexMetrics.wrapSize; b.x += HexMetrics.innerDiameter * HexMetrics.wrapSize; } Grid.MakeChildOfColumn(transform, nextColumn); currentColumn = nextColumn; } c = (b + currentTravelLocation.Position) * 0.5f; //if(pathToTravel[i].IsVisible) //{ // EnableMesh(true); //} //else //{ // EnableMesh(false); //} HexVision.AddCells(Grid.GetVisibleCells(pathToTravel[i], VisionRange)); if (currentTravelLocation.IsVisible == true) { for (; t < 1f; t += Time.deltaTime * travelSpeed) { transform.localPosition = Bezier.GetPoint(a, b, c, t); Vector3 d = Bezier.GetDerivative(a, b, c, t); d.y = 0f; transform.localRotation = Quaternion.LookRotation(d); yield return(null); } t -= 1f; } HexVision.ClearCells(); } a = c; b = Location.Position; c = b; HexVision.AddCells(Grid.GetVisibleCells(location, VisionRange)); //if (location.IsVisible) //{ // EnableMesh(true); //} if (unit.IsSomethingToAttack()) { if (unit.AttackCity) { City city = unit.AttackCity; lookTowards = city.GetHexCell().Position; float attackTime = 0; animator.SetBool("Attacking", true); for (; attackTime < fightSpeed; attackTime += Time.deltaTime) { yield return(null); } animator.SetBool("Attacking", false); if (city.HitPoints <= 0) { city.GetCityState().KillLocalUnits(city); city.SetCityState(GetComponent <Unit>().CityState); } city.UpdateUI(); } else if (unit.AttackUnit) { HexUnit unitToFight = unit.AttackUnit; lookTowards = unitToFight.Location.Position; yield return(unitToFight.LookAt(location.Position)); if (unitToFight) { float attackTime = 0; animator.SetBool("Attacking", true); unitToFight.animator.SetBool("Attacking", true); for (; attackTime < fightSpeed; attackTime += Time.deltaTime) { yield return(null); } animator.SetBool("Attacking", false); unitToFight.animator.SetBool("Attacking", false); Unit unitToFightUnitComp = unitToFight.GetComponent <Unit>(); unitToFightUnitComp.ShowHealthChange(unitToFightUnitComp.GetLastHitPointChange()); unitToFightUnitComp.UpdateUI(); if (unitToFightUnitComp.HitPoints <= 0) { unitToFight.DieAnimationAndRemove(); } } } Unit unitComp = GetComponent <Unit>(); unitComp.ShowHealthChange(unitComp.GetLastHitPointChange()); unitComp.UpdateUI(); if (unitComp.HitPoints <= 0) { DieAnimationAndRemove(); } nextColumn = Location.ColumnIndex; if (currentColumn != nextColumn) { if (nextColumn < currentColumn - 1) { a.x -= HexMetrics.innerDiameter * HexMetrics.wrapSize; } else if (nextColumn > currentColumn + 1) { a.x += HexMetrics.innerDiameter * HexMetrics.wrapSize; } Grid.MakeChildOfColumn(transform, nextColumn); currentColumn = nextColumn; } } currentTravelLocation = null; for (; t < 1f; t += Time.deltaTime * (travelSpeed * 2)) { transform.localPosition = Bezier.GetPoint(a, b, c, t); Vector3 d = Bezier.GetDerivative(a, b, c, t); d.y = 0f; transform.localRotation = Quaternion.LookRotation(d); yield return(null); } } else { currentTravelLocation = null; nextColumn = Location.ColumnIndex; if (currentColumn != nextColumn) { Grid.MakeChildOfColumn(transform, nextColumn); currentColumn = nextColumn; } } transform.localPosition = location.Position; location.UpdateVision(); orientation = transform.localRotation.eulerAngles.y; if (unit.IsSomethingToAttack()) { yield return(LookAt(lookTowards)); } ListPool <HexCell> .Add(pathToTravel); pathToTravel = null; animator.SetBool("Walking", false); }