Accomplishments
12-17-2013
Last night I got some awesome programming in on getting a random map generator up and running. It is so awesome. I got it to draw 9 random prefabs from a list and place them into the world exactly where they needed to be. The script also checked to see if it was your first time loading the map, and if it was it made your current square your home. Next on the list to do programming wise is to get it so that once you leave the first square it will add pieces to your map and delete the ones to far away. I plan on doing this by surrounding each piece with a collider so I know what piece I am leaving, and what peace I am entering. Here is my code from last night.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class MapGenerator : MonoBehaviour {
//Locations
public List<Transform> locations;
public List<Transform> currentMapPiece;
public bool firstStart = true;
public GameObject myLevel;
public List<GameObject> pieces;
public int toPlace = 9;
public int totalPieces;
public int randomPiece;
public int location;
public bool donePlacingPieces;
// Use this for initialization
void Start () {
donePlacingPieces = false;
currentMapPiece = new List<Transform>();
if (firstStart){
myLevel = pieces[0];
firstStart = false;
}
totalPieces = pieces.Count;
}
// Update is called once per frame
void Update () {
if(toPlace > 0){
randomPiece = Random.Range (0,totalPieces);
location = toPlace - 1;
currentMapPiece.Add (Instantiate (pieces[randomPiece],locations[location].position,pieces[randomPiece].transform.rotation)as Transform);
toPlace -= 1;
}
if(myLevel != null && currentMapPiece.Count >= 5 && toPlace <= 0 && !donePlacingPieces){
Destroy (currentMapPiece[4]);
currentMapPiece.Add (Instantiate (pieces[0],locations[4].position, pieces[0].transform.rotation)as Transform);
donePlacingPieces = true;
}
}
}
Sorry that it looks so bad. I need a better way to do this if you have any idea of what I can do instead please let me know.
Last night I got some awesome programming in on getting a random map generator up and running. It is so awesome. I got it to draw 9 random prefabs from a list and place them into the world exactly where they needed to be. The script also checked to see if it was your first time loading the map, and if it was it made your current square your home. Next on the list to do programming wise is to get it so that once you leave the first square it will add pieces to your map and delete the ones to far away. I plan on doing this by surrounding each piece with a collider so I know what piece I am leaving, and what peace I am entering. Here is my code from last night.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class MapGenerator : MonoBehaviour {
//Locations
public List<Transform> locations;
public List<Transform> currentMapPiece;
public bool firstStart = true;
public GameObject myLevel;
public List<GameObject> pieces;
public int toPlace = 9;
public int totalPieces;
public int randomPiece;
public int location;
public bool donePlacingPieces;
// Use this for initialization
void Start () {
donePlacingPieces = false;
currentMapPiece = new List<Transform>();
if (firstStart){
myLevel = pieces[0];
firstStart = false;
}
totalPieces = pieces.Count;
}
// Update is called once per frame
void Update () {
if(toPlace > 0){
randomPiece = Random.Range (0,totalPieces);
location = toPlace - 1;
currentMapPiece.Add (Instantiate (pieces[randomPiece],locations[location].position,pieces[randomPiece].transform.rotation)as Transform);
toPlace -= 1;
}
if(myLevel != null && currentMapPiece.Count >= 5 && toPlace <= 0 && !donePlacingPieces){
Destroy (currentMapPiece[4]);
currentMapPiece.Add (Instantiate (pieces[0],locations[4].position, pieces[0].transform.rotation)as Transform);
donePlacingPieces = true;
}
}
}
Sorry that it looks so bad. I need a better way to do this if you have any idea of what I can do instead please let me know.