//-------------------------------------- // Redefined Methods //-------------------------------------- /// <summary> /// Dos something when get the goal. /// </summary> public override void doSomethingWhenGetTheGoal() { base.doSomethingWhenGetTheGoal(); //when an enemy get the goal catchs a crystal CrystalCell cc = CurrentTarget.GetComponent <CrystalCell>(); //enemy catchs crystal if (cc != null) { cc.catchCrystal(this); Destroy(this.gameObject); } }
/// <summary> /// Gets the living crystals cells. /// </summary> /// <value>The living crystals cells.</value> public List <Cell> crystalsCells() { List <Cell> cells = new List <Cell>(); foreach (Cell cell in grid) { if (cell.Type == CellType.CRYSTAL) { CrystalCell cc = cell.GetComponent <CrystalCell>(); if (cc != null && !cc.HasCaught) { cells.Add(cell); } } } return(cells); }
/// <summary> /// Chooses a living target. Final Target (destiny) is set by a child class of Unit /// Each Unit decides what is its preferred final target /// </summary> /// <param name="_finalTargetNode">_final target node.</param> public override void chooseTarget(Node _finalTargetNode) { CrystalCell cc = FinalTarget != null?FinalTarget.GetComponent <CrystalCell> () : null; bool keepFinalTarget = cc != null && !cc.HasCaught; List <Cell> crystalCells = null; int cellIndex = 0; Node finalPreferredTarget = null; //dont keep the first final crystal cell, get a new crystal cell target if there is if (!keepFinalTarget) { crystalCells = GridGenerator.instance.crystalsCells(); //get living crystal cells if (crystalCells.Count > 0) { cellIndex = Random.Range(0, crystalCells.Count); finalPreferredTarget = crystalCells [cellIndex]; //get the final target cell } } //Enemies prefer Crystal Cells like final target base.chooseTarget(finalPreferredTarget); }