I’ve spent over 2 hours going over this and I can’t seem to find what is wrong with my coding. For some reason it just won’t move the player. This is my coding (a lot of stuff that I don’t really think is causing the problem, the real problem is at the ending):
using UnityEngine;
using System.Collections;
public class Level : MonoBehaviour {
private int levelWidth;
private int levelHeight;
public Transform grassTile;
public Transform stoneBrickTile;
private Color[] tileColors;
public Color grassColor;
public Color stoneBrickColor;
public Color spawnPointColor;
public Texture2D levelTexture;
public Entity player;
void Start () {
levelWidth = levelTexture.width;
levelHeight = levelTexture.height;
loadLevel();
}
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] == grassColor)
{
Instantiate(grassTile, new Vector3(x, y), Quaternion.identity);
}
if(tileColors[x+y*levelWidth] == stoneBrickColor)
{
Instantiate(stoneBrickTile, new Vector3(x, y), Quaternion.identity);
}
if(tileColors[x+y*levelWidth] == spawnPointColor)
{
Instantiate(grassTile, new Vector3(x, y), Quaternion.identity);
Vector3 pos = new Vector3(x, y);
player.transform.position = pos;
}
}
}
}
}
I’ve replaced the grassTile with other tiles just to see if it replaces it like it should and it does. It just doesn’t want to put my character there.