- Home /
Question by
Rickasheye · Apr 09, 2020 at 06:50 AM ·
gameobjectprefabsgenerationconnecting
Unable to generate a proper engine etc...
Im trying to generate a facility or office like building with prefabs and a script to sew those prefabs together, the only issue is that i am retarded. and i need help, sorting out this kind of issue i am having. and i would like to have the prefabs not overlapping each other to create straight pathways or make overlapping ones go overhead. The code shown below is the generator and further down is the object "PointLocation"
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Generator : MonoBehaviour
{
public GameObject[] roomPrefabs;
public GameObject startingPrefabs;
public void Start()
{
Generate();
}
public void Generate()
{
for (int i = 0; i < Random.Range(1, 3); i++)
{
PointLocation locale = startingPrefabs.GetComponent<PointLocation>();
foreach(GameObject m in locale.pointsExit)
{
GameObject newGenerated = Instantiate(roomPrefabs[Random.Range(0, roomPrefabs.Length)], m.transform.position, m.transform.rotation, startingPrefabs.transform);
newGenerated.transform.rotation = Quaternion.Euler(0, 90, 0);
startingPrefabs = newGenerated;
}
}
}
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class PointLocation : MonoBehaviour
{
public Vector3 pointEnter;
public List<GameObject> pointsExit = new List<GameObject>();
public bool noExit;
public bool norepeat = false;
public bool morethan2exits;
public void Start()
{
//Get the positions and add them
for (int i = 0; i < transform.childCount; i++)
{
if (transform.GetChild(i).tag == "ENTRY")
{
pointEnter = transform.GetChild(i).position;
}
else if (transform.GetChild(i).tag == "EXIT")
{
Transform referencedChild = transform.GetChild(i);
//Check if the point is added or not and if so add one
pointsExit.Add(referencedChild.gameObject);
}
}
}
}
https://imgur.com/WIFaQx8 this is a sample of what the code currently does. all of the objects have a set y rotation of 90 and the pivot is at the point where i would like the objects to be attached.
Comment