Skip to content

Instantly share code, notes, and snippets.

@twobob
Created March 25, 2015 16:44
Show Gist options
  • Save twobob/6de4b698a51bc0a387ec to your computer and use it in GitHub Desktop.
Save twobob/6de4b698a51bc0a387ec to your computer and use it in GitHub Desktop.
MoveWhenFar.cs
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
public class moveWhenFar : MonoBehaviour {
readonly static float TerrainSize = 256f;
GameObject player;
GameObject[] floorTiles;
public static List<GameObject> NorthTiles;
public static List<GameObject> EastTiles;
public static List<GameObject> SouthTiles;
public static List<GameObject> WestTiles;
Vector3 middleOffset;
public static List<GameObject> CompleteTileList;
// used to subsort the lists.
List<GameObject> NSlist;
List<GameObject> EWlist;
// for debug
List<Color> TileColors;
// Use this for initialization
void Start () {
// For Debug only
TileColors = new List<Color>{Color.red, new Color(1f,.3f,0f), new Color(1f,.6f,0f), new Color(1f,.9f,0f),
new Color(1f,1f,.3f),new Color(1f,1f,.6f),new Color(1f,1f,1f)};
player = GameObject.FindGameObjectWithTag("Player");
middleOffset = new Vector3(128f, 0f, 128f);
floorTiles = GameObject.FindGameObjectsWithTag("Tile");
NorthTiles = new List<GameObject>(3);
EastTiles = new List<GameObject>(3);
WestTiles = new List<GameObject>(3);
SouthTiles = new List<GameObject>(3);
CompleteTileList = new List<GameObject>(floorTiles);
NSlist = new List<GameObject>(
floorTiles
);
EWlist = new List<GameObject>(
floorTiles
);
//update lists
UpdateTilesLists ();
}
int maxTilesStackWidth = 3;
void UpdateTilesLists(){
// Get the SouthernMost
NSlist.Sort (delegate(GameObject c1, GameObject c2) {
return c1.transform.position.z.CompareTo (c2.transform.position.z); });
SouthTiles = NSlist.GetRange (0, 3);
// Get the NorthernMost
NSlist.Sort (delegate(GameObject c1, GameObject c2) {
return c2.transform.position.z.CompareTo (c1.transform.position.z); });
NorthTiles = NSlist.GetRange (0, 3);
EWlist.Sort (delegate(GameObject c1, GameObject c2) {
return c2.transform.position.x.CompareTo (c1.transform.position.x); });
EastTiles = EWlist.GetRange (0, 3);
EWlist.Sort (delegate(GameObject c1, GameObject c2) {
return c1.transform.position.x.CompareTo (c2.transform.position.x); });
WestTiles = EWlist.GetRange (0, 3);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment