public void SetAbilitySlot(int index, ScriptedAbility ability, bool isPrefab = false) { if (index < 0 || index >= Abilities.Count) { Debug.LogWarning("PlayerController::SetAbilitySlot(): Index out of range (" + index + ") for new ability: " + ability.name); return; } // If exists, remove old if (Abilities[index].Ability != null && !isPrefab) { Abilities[index].Ability.Unbind(); Destroy(Abilities[index].Ability); } if (ability != null) { // Create new Abilities[index].Ability = ability.CloneAndBind(transform); Abilities[index].Ability.Reset(); } else { Abilities[index].Ability = null; } // Raise Event RaiseAbilitySlotChanged(index); }
void Start() { // take the abilities and make up a reel of them according to weights. int t_Size = 0; foreach (ScriptedAbility single in abilities) { t_Size += single.weight; } reelAbilities = new ScriptedAbility[t_Size]; int index = 0; foreach (ScriptedAbility single in abilities) { for (int i = 0; i < single.weight; i++) { reelAbilities[index] = single; index++; } } for (int i = 0; i < reelAbilities.Length; i++) { //Shuffle the deck of cards. //Grab the first index, move it to a new location of Random.Range(0, reelAbilitys.Length - 1) //Grab the following index and repeat the next step. foreach in abilities. int index1 = Random.Range(0, reelAbilities.Length); int index2 = Random.Range(0, reelAbilities.Length); ScriptedAbility temp = reelAbilities[index2]; reelAbilities[index2] = reelAbilities[index1]; reelAbilities[index1] = temp; } Image[] tempImages = transform.GetComponentsInChildren <Image>(); buttonsOfPower = transform.parent.GetComponentsInChildren <PowerupIdentity>(); foreach (PowerupIdentity identityPI in buttonsOfPower) { identityPI.enabled = false; } //PowerupIdentity // this list includes the reel, so copy everything else into an array index = 0; images = new Image[tempImages.Length - 1]; foreach (Image image in tempImages) { //if (image.gameObject.GetComponent("PowerupIdentity") != null) //{ // clickableIcon = image.gameObject;//.GetComponent<PowerupIdentity>(); //} if (image.gameObject != gameObject) { images[index] = image; index++; } } if (playButton.interactable) { if (powerUpsAvalible >= 1) { playButton.interactable = true; } else { playButton.interactable = false; } } myButton = MyButtonOfPower.GetComponent <Button>(); startPosition = transform.position.y; offset = images[1].transform.position.y - images[0].transform.position.y; faction_OnePercentValue = (startPosition + offset) - startPosition; }