Skip to content

Instantly share code, notes, and snippets.

@IronMonk-UK
IronMonk-UK / AIUnit.cs
Created May 11, 2016 19:36
The final collection of classes for my Final Project
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class AIUnit : Unit {
GameManager gm;
Pathfinding path;
Grid grid;
Renderer rend;
// 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
// 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
@IronMonk-UK
IronMonk-UK / AIUnit.cs
Created May 10, 2016 20:06
Classes changed in the latest implementation
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class AIUnit : Unit {
GameManager gm;
Pathfinding path;
Grid grid;
Renderer rend;
@IronMonk-UK
IronMonk-UK / AIUnit.cs
Created April 25, 2016 17:48
All code towards the project up to 25/04/16
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class AIUnit : Unit {
GameManager gm;
Pathfinding path;
Grid grid;
Renderer rend;
@IronMonk-UK
IronMonk-UK / AIUnit.cs
Created April 16, 2016 12:16
Scripts relating to the current AI
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class AIUnit : Unit {
Renderer rend;
GameManager gm;
Pathfinding path;
@IronMonk-UK
IronMonk-UK / AIUnit Snippet
Last active April 7, 2016 13:07
AI Snippets
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
foreach userUnit u
userUnit target
pathTarget = u.node
if indexOf u.node + 1 <= movement + 1
bool inRange = true
if inRange
List<UserUnit> UnitsInRange
@IronMonk-UK
IronMonk-UK / GameManager.cs
Created March 21, 2016 16:00
Post-Implementation of the Inventory System
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
public class GameManager : MonoBehaviour
{
public static GameManager gm;
@IronMonk-UK
IronMonk-UK / GameManager.cs
Created March 13, 2016 13:39
13/03 Iteration of Final Project
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
public class GameManager : MonoBehaviour
{
public static GameManager gm;