- Home /
,Identifying direction of GameObject in Range
My Question is much more complex than the heading suggests.
I am very new to programming and unity but I learn quickly, I have a few gaps that is leading me to inefficient paths, and I feel very lost at the moment, please help!
I have a random map generator, that generates a 'genesis' map on each 8 sides (corners included) of the center map. To add complexity, the bottom center and left generates 'snowLands", the left center and top generates 'grassLands', top center and right generates "groundLands", and finally, right center and bottom generates "rockLands". Each different type of land is generated by it's associated 'type'-MapGenerater GameObject that has their choice of prefabs to generate the map to favor the type of land, and spawn appropriate trees and so forth, all connected to the same map generator script.
When a map type is generated, it creates an associated GameObject trigger type in the middle of the map, that has a child gameobject "MapOverlay" covering the map with a collider. Each Trigger located in the center of each map has the same LandTriggerScript
public bool isLandOpen = false;
public bool hasNorthLand = false;
public bool hasEastLand = false;
public bool hasSouthhLand = false;
public bool hasWestLand = false;
public bool hasNorthEastLand = false;
public bool hasSoutEastLand = false;
public bool hasSouthWestLand = false;
public bool hasNorthWest = false;
My center map has 4 triggers, one for each side, and their Booleans are set accordingly.
This is where I need help...
When isLandOpen goes to true (when an adjacent land's trigger is triggered), The Overlay will be turned off and access will be granted to the map.
The newly open map must then also Check (in range) the surrounding area for adjacent maps to see if it has to generated a map on the sides that are "false" (based on probability of type) and turn those Booleans true
When the newly founded map's center trigger is triggered, it will open all adjacent lands (accept corners, and lands that have already been opened), and generate new locked land on the border of those open lands, where lands have not yet been generated.
What is the smart way to do this?
I believe I have everything covered, I just need the syntax;
public class LandTriggerScript : MonoBehaviour
{
public bool isLandOpen = false;
public bool hasNorthLand = false;
public bool hasEastLand = false;
public bool hasSouthhLand = false;
public bool hasWestLand = false;
public bool hasNorthEastLand = false;
public bool hasSoutEastLand = false;
public bool hasSouthWestLand = false;
public bool hasNorthWest = false;
public GameObject[] adjacentTriggers;
public void PrepareTriggers()
{
Collider[] triggers = Physics.OverlapSphere(transform.position, 30);
foreach (Collider col in triggers)
{
if (col.gameObject.tag == "MapTrigger")
{
//add game object to the array of gameobjects named adjacentTriggers
}
}
for(a = 0 ; a < adjacentTriggers.length; a++)
{
//if the gameobject's x axes is smaller than transform's x value, set the transform's hasWestLand boolean true,
//as well as the opposite side for the target game object...and so on for all 8 sides.
//check if adjacent land is open, open only if it is either north/east/south/west and set their isLandOpenValue to true.
//create closed adjacent lands to the newly open land where there is no land on all 8 sides.
}
}
}