So… I’m writing some code (shocking, right?) and it’s getting the wrong values. The only value I really care about is the X and Y position of the GameObject End in the GameObject Room1, as I am creating a generation script to randomly generate rooms. The code I am using returns a very different value than what is actually there. Code is below.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GenerationScript : MonoBehaviour
{
public GameObject Room1;
public GameObject Room2;
public GameObject Room3;
public GameObject Room4;
public GameObject Room5;
public GameObject Room6;
public GameObject EndRoom;
private int Generated;
public int GenerateAmount;
private int RandomRoom;
public GameObject PrevRoom;
private GameObject NextRoom;
void Start()
{
Debug.Log(PrevRoom.transform.GetChild(0).transform.position.x);
Debug.Log(PrevRoom.transform.GetChild(0).transform.position.y);
Debug.Log(PrevRoom);
Generated = 0;
do
{
RandomRoom = 2;//Random.Range(0,6);
if (RandomRoom == 1)
{
NextRoom = Instantiate(Room2);
}
if (RandomRoom == 2)
{
NextRoom = Instantiate(Room3);
}
if (RandomRoom == 3)
{
NextRoom = Instantiate(Room4);
}
if (RandomRoom == 4)
{
NextRoom = Instantiate(Room5);
}
if (RandomRoom == 5)
{
NextRoom = Instantiate(Room6);
}
NextRoom.transform.position = new Vector3(PrevRoom.transform.GetChild(0).transform.position.x, PrevRoom.transform.GetChild(0).transform.position.y, 0);
PrevRoom = NextRoom;
Generated = Generated + 1;
} while (Generated < GenerateAmount);
NextRoom = Instantiate(EndRoom);
NextRoom.transform.position = new Vector3(PrevRoom.transform.GetChild(0).transform.position.x, PrevRoom.transform.GetChild(0).transform.position.y, 0);
}
}
Also video for more clarity