I’m trying to make a 2D top down RPG style game and it was going fine until I tried to add a spawn point. When I added the 3-4 lines of code that i used for the spawn point, i tested the game and noticed it didn’t spawn me at the spawn point. When I went to where the spawn point was supposed to be, I noticed that the level stopped loading once it reached the spawn point.
Here is the level C# Script, the lines of code for the spawn point will be surrounded by “!”.
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);
Vector2 pos = new Vector2(x, y);
player.transform.position = pos;
}!
}
}
}
}
Any idea what happened?