Can someone tell me what’s wrong with this code? I checked the position of the controller object that the script is attached to and it looks like it didn’t move.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class randomlevel : MonoBehaviour {
public int randomness;
public int lvl_size;
private Vector3[] ways;
void start () {
Vector3[] ways = new Vector3[4] {new Vector3(0,0,5), new Vector3(0,0,-5), new Vector3(5,0,0), new Vector3(-5,0,0)};
int thatway = 0;
List<Vector3> places = new List<Vector3> ();
places.Add (transform.position);
for (int i = 0; i <= lvl_size; i++) {
transform.position = new Vector3 (transform.position.x + ways[thatway].x, 0, transform.position.z + ways[thatway].z);
places.Add (transform.position);
print("It works");
}
}
}
Note, the randomness property is not yet used, but once I get this problem solved I will add that part in. At this point the position of the controller object should end up at (0,0,25) because I set lvl_size to 5.
Any help would be appreciated.
Hi
I’m not sure exactly what that code is supposed to do - you didn’t mention that in your question! 
There is an obvious issue though - you have called your function ‘start’, not ‘Start’. C# is case sensitive, so your function won’t be getting called at all automatically. If you’re relying on that, then none of your code will be getting called.
I’m not sure where the ‘print’ function came from either?
After that, the code doesn’t look like it will actually do a great deal of work - it is effectively just fulling in a list of vector3s by changing the transform of random level repeatedly. Maybe what you’re looking for is something more along the lines of:
public class randomlevel : MonoBehaviour
{
public int randomness;
public int lvl_size;
//private Vector3[] ways; //this is redundant as we define a list of ways inside the start function!
// Start function gets called when randomlevel is initialized (note capital S!!)
void Start()
{
//our potential ways
Vector3[] ways = new Vector3[4] { new Vector3(0, 0, 5), new Vector3(0, 0, -5), new Vector3(5, 0, 0), new Vector3(-5, 0, 0) };
//our list of places
List<Vector3> places = new List<Vector3>();
//starting place is the transform of the randomlevel object?
Vector3 current_place = transform.position;
//add the first place
places.Add(current_place);
//add a set of extra places along a randomly generated path
for (int i = 0; i <= lvl_size; i++)
{
int thatway = 0; //replace 0 with random number between 0 and ways.Length (see Random.Range)
//add the 'way' vector to the current place to get the next position
current_place += ways[thatway];
//store current place in
places.Add(current_place);
//print something nice!
Debug.Log("Added place " + current_place.ToString());
}
//presumably now we'd do something with our places list?
}
}
That has a few floors, but might get you started 