this is the error
KeyNotFoundException: The given key was not present in the dictionary.
System.Collections.Generic.Dictionary`2[Point,TileScript].get_Item (Point key) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:150)
LevelManager.CreateLevel () (at Assets/Scripts/LevelManager.cs:72)
LevelManager.Start () (at Assets/Scripts/LevelManager.cs:25)
and this is my code
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LevelManager : MonoBehaviour
{
//create GameObject to place tiles
[SerializeField]
private GameObject tilePrefabs;
[SerializeField]
private CameraMovement cameraMovement;
public Dictionary<Point,TileScript> Tiles { get; set; }
//get the tiles
public float TileSize
{
get { return tilePrefabs[0].GetComponent<SpriteRenderer>().sprite.bounds.size.x; }
}
// Use this for initialization
void Start()
{
//Use to execute create level function
CreateLevel();
}
// Update is called once per frame
void Update()
{
}
//Create New Level
private void CreateLevel()
{
Tiles = new Dictionary<Point, TileScript>();
string[] mapData = ReadLevelText();
//get the total overall tiles
int mapX = mapData[0].ToCharArray().Length;
int mapY = mapData.Length;
Vector3 maxTile = Vector3.zero;
//place the tiles to the left corner
Vector3 worldStart = Camera.main.ScreenToWorldPoint(new Vector3(0, Screen.height));
//number of tiles
for (int y = 0; y < mapY; y++)
{
//get the pattern of the tiles
char[] newTiles = mapData[y].ToCharArray();
for (int x = 0; x < mapX; x++)
{
// get the number of tiles
try
{
PlaceTile(newTiles[x].ToString(), x, y, worldStart);
}
catch (IndexOutOfRangeException)
{
}
}
maxTile = Tiles[new Point(mapX - 1, mapY - 1)].transform.position;
}
cameraMovement.SetLimits(new Vector3(maxTile.x + TileSize, maxTile.y - TileSize));
}
//Place tiles
private void PlaceTile(string tileType, int x, int y, Vector3 worldStart)
{
//"1"=1
int tileIndex = int.Parse(tileType);
//used to place tiles
TileScript newTile = Instantiate(tilePrefabs[tileIndex]).GetComponent<TileScript>();
//use the new tile variable to change the position of the t
newTile.Setup(new Point(x, y), new Vector3(worldStart.x + (TileSize * x), worldStart.y - (TileSize * y), 0));
Tiles.Add(new Point(x, y), newTile);
}
private string[] ReadLevelText()
{
//read the resources
TextAsset bindData = Resources.Load("level") as TextAsset;
//split the data
string data = bindData.text.Replace(Environment.NewLine, string.Empty);
return data.Split('-');
}
}