Help with c# code used for rendering levels from files
I have some code that I made, and it is not behaving properly. I don't know what is wrong with it, and will accept any and all debugging advice. [code] using UnityEngine; using System.Collections;
public class Level : MonoBehaviour {
private int levelWidth;
private int levelHeight;
public Transform floorTile;
public Transform wallTile;
private Color[] tileColors;
public Color floorColor;
public Color wallColor;
public Texture2D levelTexture;
public Entity player;
void Start()
{
levelWidth = levelTexture.width;
levelHeight = levelTexture.height;
loadLevel();
}
void Update()
{
}
void loadLevel()
{
tileColours = new Color[levelWidth * levelHeight];
tileColours = levelTexture.GetPixels();
for(int y = 0; y < levelHeight; y++)
{
for(int x = 0; x < levelWidth; x++)
{
if (tileColours[x * y * levelWidth] == grassColor)
{
Instantiate(grassTile, new Vector3(x, y), Quaternion.identity);
}
if (tileColours[x * y * levelWidth] == wallColor)
{
Instantiate(wallTile, new Vector3(x, y), Quaternion.identity);
}
}
}
}
} [/code] thank you!
Comment
tileColours[x * y * levelWidth]
should be =
tileColours[x + y * levelWidth]
Also just use a Tile$$anonymous$$ap.
Your answer
Follow this Question
Related Questions
Help with trying to make a 2D character move in all four directions via the arrow keys 2 Answers
Detecting a button click 1 Answer
How to add alternate idle directions to a top-down game 0 Answers
[2D] How to grab and throw an object backward? 2 Answers
Dialogue script shows previous sentences after a while 0 Answers