void Awake() { RectTransform rectTransform = GetComponent <RectTransform>(); areaSize = rectTransform.sizeDelta; if (areaSize.x > areaSize.y) { tileHeight = areaSize.y / 5; tileWidth = tileHeight; } else { tileHeight = areaSize.x / 5; tileWidth = tileHeight; } fightCharacters = new FightCharacter[10]; for (int i = 0; i < 10; i++) { GameObject character = Instantiate(characterPrefab) as GameObject; FightCharacterAnimatorScript animatorScript = character.GetComponent <FightCharacterAnimatorScript>(); character.transform.parent = transform; character.transform.localRotation = Quaternion.identity; int gridX, gridY; if (i < 5) { // -2 because we have 5 heroes per side so the third goes to middle // i:th hero goes from 0 to 5. gridX = centerColumn - 2 + i; gridY = team1TeamRow; } else { // same as in if true part but -5 more because we are handling next team of heroes gridX = centerColumn - 7 + i; gridY = team2TeamRow; } Vector3 newPosition = getWorldPosition(gridX, gridY); character.transform.localPosition = newPosition; // Scale char to tile size character.transform.localScale = Vector3.one * tileHeight; FightCharacter fightCharacter = new FightCharacter(); fightCharacter.animatorScript = animatorScript; fightCharacter.gridX = gridX; fightCharacter.gridY = gridY; fightCharacter.teamGridX = gridX; fightCharacter.teamGridY = gridY; fightCharacter.transform = character.transform; fightCharacters[i] = fightCharacter; } }
public void Reset() { for (int i = 0; i < 10; i++) { FightCharacterAnimatorScript script = fightCharacters[i].animatorScript; script.Reset(); if (i < 5) { script.Face(script.UP); } else { script.Face(script.DOWN); } } }