#Problem

1 messages · Page 1 of 1 (latest)

grizzled forge
#

gimme a minute-

#

Checkers:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Checkers : MonoBehaviour
{
    public bool isScanned = false;
    bool hit;
    bool isOccupied = false;
    public bool isReady = false;
    public int CastDistance = 10;

    void Start()
    {
        if (isScanned == false)
        {
            hit = Physics.BoxCast(transform.position,transform.localScale, transform.localScale, Quaternion.identity, CastDistance);
            if (hit)
            {
                isOccupied = true;
                isScanned = true;
                Debug.Log("isOccupied");
            }
            else
            {
                isOccupied = false;
                isScanned = true;
                Debug.Log("isNotOccupied");
            }
        }

    }
    void Update()
    {
        if (isOccupied == false && isScanned == true && isReady == false)
        {
            isReady = true;
            Debug.Log("isReady");
        }
    }
}
#

Scanner:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Scanner : MonoBehaviour
{
    public List<Checkers> CheckersList;
    public GameObject thisRoom;
    public GameObject RoomParent;
    public GameObject CheckersParent;
    void Start()
    {
       
    }
    void Update()
    {
        foreach (Checkers Checker in CheckersList)
        {
            Debug.Log("Checking");
            if (Checker.isReady == false && Checker.isScanned == true)
            {
                Destroy(thisRoom);
            }
            else
            {
                RoomParent.SetActive(true);
                Destroy(CheckersParent);
            }
        }
    }
}
#

Spawners:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RoomSpawning : MonoBehaviour
{
    public List<Transform> Spawners;
    public List<GameObject> Rooms;
    public GameObject Scanner;
    private int SpawnerNum = 0;
    void OnEnable()
    {
        GameObject manager = GameObject.Find("RoomsManager");
        RoomsManager managerProperty = manager.GetComponent<RoomsManager>();

        //GameObject area = Scanner;
        //Scanner areaProperty = area.GetComponent<Scanner>();

        while (SpawnerNum+1 <= Spawners.Count && managerProperty.RoomCount < managerProperty.maxRoom )
        {
            managerProperty.RoomCount++;
            Instantiate(Rooms[Random.Range(0, Rooms.Count - 1)], Spawners[SpawnerNum].position, Spawners[SpawnerNum].rotation);
        }
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
#

Manager(this thing only tell the game the max amount of rooms):

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RoomsManager : MonoBehaviour
{
    public static RoomsManager instance;
    public int RoomCount = 0;
    public int maxRoom = 30;

    void Start()
    {

    }

    void Update()
    {

    }
}
dark cape
#

The simplest approach would be to divide the space into a grid and use it's cells to spawn rooms. Then you can mark them as occupied after spawning in something.

#

Alternatively, use a node graph system, where each room can have several connections in predefined offsets. Then just fill the connected nodes as you spawn them.

grizzled forge
#

the grid thing can work, but the room arent the same size and are directly connected from a doorway to the next and I wanted to make my script works since it would be easier from then on(it will be use for the other aspect/project that using a grid wouldnt work), I already have things planned out and the only thing stopping me is a technicality so imo it'd be much better to fix the one thing that been bugging me then to start over

dark cape
#

Even if you want to keep with current approach, you need to rethink the logic. At the moment it's extremely nonsensical. Try writing down the algorithm in simple words to understand what's happening now and what you actually want to happen.

grizzled forge
#

alr, thanks

#

I will do that

grizzled forge
#

hm-

grizzled forge
#

yay- Im nearly there

grizzled forge
#

YESsss