This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class AIUnit : Unit { | |
GameManager gm; | |
Pathfinding path; | |
Grid grid; | |
Renderer rend; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Makes tiles populated by units unwalkable, so they cannot be moved to, or stopped on | |
void BlockUnitTiles() { | |
// If the current unit is a User unit, and moving | |
if (userUnits.Contains(units[currentUnitIndex]) && units[currentUnitIndex].moving) { | |
// For every unit | |
foreach(Unit u in units) { | |
// If the unit is not the current unit | |
if(u != units[currentUnitIndex]) | |
// Set the walkable bool on the node of the populated tile to false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Method to add in forest tiles to the map | |
void AddForests() { | |
// A for loop is run, with i starting at 0, and increasing until it has reached a sixth | |
// of the total tiles, calculated by multiplying the X and Y map lengths, and dividing | |
// the result by 6 | |
for (int i = 0; i < Mathf.RoundToInt((worldSize.x * worldSize.y) / 6); i++) { | |
// Random X and Y variables are generated | |
int x = Mathf.RoundToInt(Random.Range(0, worldSize.x)); | |
int y = Mathf.RoundToInt(Random.Range(0, worldSize.y)); | |
// If the forest bool of the tile attached to the node with the random |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class AIUnit : Unit { | |
GameManager gm; | |
Pathfinding path; | |
Grid grid; | |
Renderer rend; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class AIUnit : Unit { | |
GameManager gm; | |
Pathfinding path; | |
Grid grid; | |
Renderer rend; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class AIUnit : Unit { | |
Renderer rend; | |
GameManager gm; | |
Pathfinding path; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public override void turnUpdate() | |
{ | |
//A boolean added in preparation, should it be required | |
findUnits = true; | |
//I created a List within the GameManager to store specifically User Units, allowing the AI to loop through them | |
foreach (UserUnit u in gm.userUnits) | |
{ | |
//The path target is set to the unit, creating a path from the AI Unit to the User Unit | |
path.target.transform.position = u.currentTile._pos; | |
//A debug log to ensure results were being picked up correctly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foreach userUnit u | |
userUnit target | |
pathTarget = u.node | |
if indexOf u.node + 1 <= movement + 1 | |
bool inRange = true | |
if inRange | |
List<UserUnit> UnitsInRange | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.UI; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class GameManager : MonoBehaviour | |
{ | |
public static GameManager gm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.UI; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class GameManager : MonoBehaviour | |
{ | |
public static GameManager gm; |
NewerOlder