public HeroUnit GenerateHero(UnitStats stats, int rarity, StatType primaryStat, int cost) { HeroUnit hero = Instantiate(heroPrefab); hero.name = StatHelper.MakeName(); hero.rarity = rarity; hero.SetStats(stats); hero.cost = cost; Ability[] abilites = { }; if (primaryStat == StatType.STR) { abilites = strAbilities; } else if (primaryStat == StatType.INT) { abilites = Random.Range(0.0f, 1.0f) > 0.5f ? intDmgAbilities : intSupAbilities; } else if (primaryStat == StatType.DEX) { abilites = dexAbilities; } UnitAbilityController abilityRoot = hero.GetAbilityController(); foreach (Ability abilityPrefab in abilites) { Ability ability = Instantiate(abilityPrefab); ability.transform.parent = abilityRoot.transform; ability.transform.localPosition = Vector3.zero; } abilityRoot.UpdateAbilityList(); abilityRoot.enabled = false; if (abilites == intSupAbilities) { hero.targettingAlignment = TargettingAlignment.Friendly; } UnitMovementController movementController; if (abilites == strAbilities) { movementController = hero.gameObject.AddComponent <MeleeUnitMovementController>(); } else { movementController = hero.gameObject.AddComponent <RangedUnitMovementController>(); } movementController.Disable(); int seatIndex = Random.Range(0, seats.Count); Transform seat = seats[seatIndex]; seats.RemoveAt(seatIndex); hero.transform.position = seat.position; heroList.AddHero(hero); return(hero); }
private void Awake() { unit = GetComponentInParent <Unit>(); abilityController = unit.GetComponentInChildren <UnitAbilityController>(); }
void Awake() { abilityController = GetComponentInChildren <UnitAbilityController>(); abilityController.SetUnit(this); }