Crashes in start() when I put this line
paths[0].sections[0] = new Section1();
/////////////////////////////////////
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Level : MonoBehaviour {
public int typesOfSections = 1;
public int tileSize = 2;
public int generationDistance = 100;
//
// To store all paths
public Path[] paths = new Path[3];
//
// Player gameobject to access position
public GameObject player;
//
// Assign in editor
public GameObject[] allTiles;
public GameObject[] allWalls;
public GameObject[] allPoints;
//
// Path Class
public class Path {
public int maxSections = 10;
public Section1[] sections = new Section1[3];
public int typesOfSections = 1;
public int tileSize = 2;
public int generationDistance = 100;
public Path() {
//sections = new Section1[maxSections];
return;
}
public void addNewSection() {
return;
}
}
//
// Section Class
public class Section1 : Path {
public Vector3 position;
public int width = 9;
public int length;
public int baseLength = 100;
public SectionComponent[] tiles;
public SectionComponent[] walls;
public SectionComponent[] points;
public Section1() {
tiles = new SectionComponent[200];
length = baseLength;
for (int i = 0; i < width; i++) {
for (int j = 0; j < length; j++) {
int xPos = i * tileSize;
int yPos = 0;
int zPos = j * tileSize;
Vector3 newPosition = new Vector3(xPos, yPos, zPos);
tiles[i] = new SectionComponent(newPosition);
}
}
return;
}
public void GenerateTiles() {
for (int i = 0; i < width; i++) {
for (int j = 0; j < length; j++) {
int xPos = i * tileSize;
int yPos = 0;
int zPos = j * tileSize;
Vector3 newPosition = new Vector3(xPos, yPos, zPos);
tiles[i] = new SectionComponent(newPosition);
}
}
return;
}
}
//
// SectionComponent Class
public class SectionComponent : Section1 {
public Vector3 componentPosition;
public GameObject gameObject;
//
// Constructor
public SectionComponent(Vector3 position) {
componentPosition = position;
return;
}
}
//
// Unique Sections
//
// ZigZagWall Section Class
public class ZigZagWall : Section1 {
int numWalls;
int minNumWalls = 2;
int maxNumWalls = 6;
public ZigZagWall() {
numWalls = Random.Range(minNumWalls, maxNumWalls);
length = numWalls * 10 + numWalls + baseLength;
GenerateTiles();
return;
}
}
//
// Use this for initialization
void Start() {
paths[0] = new Path();
paths[0].sections[0] = new Section1();
//for (int i = 0; i < paths[0].sections[0].tiles.Length; i++) {
// Instantiate(allTiles[0], new Vector3 (0.0f, 0.0f, 0.0f), transform.rotation);
// }
//Instantiate(allTiles[0]);
return;
}
//
// Update is called once per frame
void Update() {
MoveLevel();
return;
}
//
// Move Level Transform With Player
private void MoveLevel() {
float zPos = player.transform.position.z;
Vector3 newPos = new Vector3(0.0f, 0.0f, zPos);
transform.position = newPos;
return;
}
//
// Initiates component
public void InstantiateComponent() {
return;
}
}
↧