Children and parents in relative space
My question is mainly: If objects are grandchildren, does that effect transform.position, this.gameObject, or GameObject.FindGameObjectsWithTag()?
To elaborate, I have lots of empty game objects that I'm using to detect cover in a stealth game. These empty game objects are children of walls which are, in turn, children of prefabs that include the walls and floor. Using the code below, I am trying to find the end of walls. It is giving me lots of funky points and null values though. If the child/parent relationship wouldn't effect anything, the question becomes: What am I not understanding? because I've gone over the logic a hundred times and don't see a problem so I can only assume I'm using a command wrong. Thanks for looking!
~Rangr
(Assume that FindClosest works and does what it sounds like)
(Also, I repeat for each cardinal direction starting at the first if statement but it's the same code for each with directional changes)
List<GameObject> lefts = new List<GameObject>();
List<GameObject> rights = new List<GameObject>();
GameObject[] obj = GameObject.FindGameObjectsWithTag("Cover");
foreach(GameObject go in obj){
if(go.transform.position != transform.position && (Mathf.Round(go.transform.eulerAngles.y) == Mathf.Round(transform.eulerAngles.y) && Mathf.Round(transform.eulerAngles.y) == 0f))
{
if(go.transform.position.x == transform.position.x)
{
if(go.transform.position.z < transform.position.z)
{
if(FindClosest(GameObject.FindGameObjectsWithTag("Cover")).transform.position != transform.position)
{
lefts.Add(go);
}
}
else if(go.transform.position.z > transform.position.z)
{
if(FindClosest(GameObject.FindGameObjectsWithTag("Cover")).transform.position != transform.position)
{
rights.Add(go);
}
}
}
}