Heres a picture and below is the code I added.
![alt text][1]
[1]: /storage/temp/35049-screenshot+(75).png
using UnityEngine;
using System.Collections;
public class Levels : MonoBehaviour {
private int levelWidth;
private int levelHeight;
public Transform NcolWoodOneTile;
public Transform NcolGrassOneTile;
private Color[] tileColors;
public Color NcolWoodOneColor;
public Color NcolGrassOneColor;
public Color SpawnPointColor;
public Texture2D levelTexture;
public Entity Player;
// Use this for initialization
void Start () {
levelWidth = levelTexture.width;
levelHeight = levelTexture.height;
loadLevel ();
}
// Update is called once per frame
void Update () {
}
void loadLevel () {
tileColors = new Color[levelWidth * levelHeight];
tileColors = levelTexture.GetPixels ();
for(int y = 0; y < levelHeight; y++)
{
for(int x = 0; x < levelWidth; x++)
{
if(tileColors[x+y*levelWidth] == NcolWoodOneColor)
{
Instantiate(NcolWoodOneTile, new Vector3(x, y), Quaternion.identity);
}
if(tileColors[x+y*levelWidth] == NcolGrassOneColor)
{
Instantiate(NcolGrassOneTile, new Vector3(x, y), Quaternion.identity);
}
if(tileColors[x+y*levelWidth] == SpawnPointColor)
{
Instantiate(NcolGrassOneTile, new Vector3(x, y), Quaternion.identity);
Vector2 pos = new Vector2(x, y);
Player.transform.position = pos;
}
}
}
}
}
↧