Skip to content

Instantly share code, notes, and snippets.

@twobob
Created March 25, 2015 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twobob/2f53c1daa835c54648bd to your computer and use it in GitHub Desktop.
Save twobob/2f53c1daa835c54648bd to your computer and use it in GitHub Desktop.
UpdateGridOnTrigger.cs
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class UpdateGridOnTrigger : MonoBehaviour {
MonoBehaviour script;
readonly static float TerrainSize = 256f;
void Start(){
// Get script references
script = GameObject.Find ("MovementManager").gameObject.GetComponent<moveWhenFar>();
}
bool isContainedInList(GameObject obj, List<GameObject> list){
return list.Contains(obj);
}
void OnTriggerEnter(){
// do this based on Lists
// North / South, East / West Lists
/*
* check the lists -
* Prefer North / South over East West (doesn't matter)
* Corners are now implicitly handled by simply testing both lists
*/
// North
if (isContainedInList(gameObject, moveWhenFar.NorthTiles)) {
// Move south tiles North and update the tags.
for (int i = 0; i < moveWhenFar.SouthTiles.Count; i++) {
moveWhenFar.SouthTiles[i].transform.position = new Vector3(
moveWhenFar.SouthTiles[i].transform.position.x,
moveWhenFar.SouthTiles[i].transform.position.y,
moveWhenFar.SouthTiles[i].transform.position.z + (3* TerrainSize));
// Center
}
//North
}
// South
if (isContainedInList(gameObject, moveWhenFar.SouthTiles)) {
// Move north tiles South and update the tags.
for (int i = 0; i < moveWhenFar.NorthTiles.Count; i++) {
moveWhenFar.NorthTiles[i].transform.position = new Vector3(
moveWhenFar.NorthTiles[i].transform.position.x,
moveWhenFar.NorthTiles[i].transform.position.y,
moveWhenFar.NorthTiles[i].transform.position.z - (3* TerrainSize));
}
//South
}
// East
if (isContainedInList(gameObject, moveWhenFar.EastTiles)) {
// Move West tiles East and update the tags.
for (int o = 0; o < moveWhenFar.WestTiles.Count; o++) {
moveWhenFar.WestTiles[o].transform.position = new Vector3(
moveWhenFar.WestTiles[o].transform.position.x + (3* TerrainSize),
moveWhenFar.WestTiles[o].transform.position.y,
moveWhenFar.WestTiles[o].transform.position.z );
}
//East
}
// West
if (isContainedInList(gameObject, moveWhenFar.WestTiles)) {
// Move south tiles North and update the tags.
for (int i = 0; i < moveWhenFar.EastTiles.Count; i++) {
moveWhenFar.EastTiles[i].transform.position = new Vector3(
moveWhenFar.EastTiles[i].transform.position.x - (3* TerrainSize),
moveWhenFar.EastTiles[i].transform.position.y,
moveWhenFar.EastTiles[i].transform.position.z );
}
//West
}
if (script == null)
return;
script.SendMessage ("UpdateTilesLists", SendMessageOptions.DontRequireReceiver);
//Ontrigger
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment