Hey there, people.
This script is turning me into a MENTAL CASE, in that, when looking at the GameObjects that it creates, it is
setting the very first Floor Number to 49 in the FloorLevelInformation_Script, instead of 0.
All of the other WallsGameObjects(Clone) after this one, have the correct FloorNumber on them, including the last one, that also has the FloorNumber as 49.
I have a feeling the error is on line 41, which is:
TheFloors[FloorCount] = new _theFloor();
because I am lacking in the knowledge of how to allocate memory for this array, when in this for() loop.
THE OBJECTIVE: I have a GameObject created, that is a PREFAB. This is that line:
public GameObject Floor; // This is the line that I add the prefab to.
What is happening here, is that in the very first WallsGameObject(Clone) in the Hierarchy, you see in the inspector, under FloorLevelInformation_Script (Script), the Floor Number starts with 49. The very next WallsGameObject(Clone), in the FloorLevelInformation_Script, has the number 0.
The FloorLevelInformation_Script is a script on the WallsGameObject prefab.
Any help will be VERY MUCH APPRECIATED…
//========================================================
// ElevatorManagerScript
//========================================================
using UnityEngine;
using System.Collections;
using System;
[System.Serializable]
public class ElevatorManagerScript : MonoBehaviour
{
public int FloorCounter;
public int FloorPlus1;
public GameObject FloorLevelInformation;
public GameObject Floor;
public int NumberOfFloors;
public float floorLocationY = 0.0f;
public GameObject[] Floors;
//===================================
// The class for my floor GameObject
//===================================
public class _theFloor
{
public GameObject _floor;
public int FloorNumber;
public float locationY;
}
//==============================================
// The following line allocates 100 items in _theFloor array.
//==============================================
public _theFloor[] TheFloors = new _theFloor[100];
//===========================================
public void Start ()
{
FloorCounter = 0;
//TheFloors[99] = new _theFloor();
//TheFloors = new _theFloor[0];
for (int FloorCount = 0; FloorCount < NumberOfFloors; FloorCount++)
{
Debug.Log("FloorCounter: " + FloorCounter);
//TheValueOfx = FloorCount;
TheFloors[FloorCount] = new _theFloor();
TheFloors[FloorCount]._floor = Floor;
TheFloors[FloorCount].FloorNumber = FloorCounter;
TheFloors[FloorCount].locationY = floorLocationY;
Floors[FloorCount] = Instantiate(TheFloors[FloorCount]._floor, new Vector3(0, TheFloors[FloorCount].locationY, 0), Quaternion.identity) as GameObject;
Floors[FloorCount].SetActive(true);
FloorLevelInformation.GetComponent<FloorLevelInformation_Script>().FloorNumber = FloorCounter;
floorLocationY += 3.215f;
FloorCounter++;
}
}
//=============================================
// Update is called once per frame
public void Update ()
{
}
}
//==========================================================================
// FloorLevelInformation_Script, which is part of the WallsGameObject prefab object.
//==========================================================================
using UnityEngine;
using System.Collections;
public class FloorLevelInformation_Script : MonoBehaviour
{
public int FloorNumber;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}