Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

Object reference not set to instance of an object?

$
0
0
**This is the error message I am getting.. I am a beginner of coding but it was actually a tutorial on youtube I followed and I can't see what error I made even though I replayed the video many times. Thanks for any help :D** NullReferenceException: Object reference not set to an instance of an object LevelManager.PlaceTile (System.String tileType, Int32 x, Int32 y, Vector3 worldStart) (at Assets/Scripts/LevelManager.cs:60) LevelManager.Createlevel () (at Assets/Scripts/LevelManager.cs:49) LevelManager.Start () (at Assets/Scripts/LevelManager.cs:23) ## This is my script ## using System.Collections; using System.Collections.Generic; using UnityEngine; using System; public class LevelManager : MonoBehaviour { [SerializeField] private GameObject[] tilePrefabs; [SerializeField] private CameraMovement cameraMovement; public float TileSize { get { return tilePrefabs[0].GetComponent ().sprite.bounds.size.x; } } // Use this for initialization void Start () { Createlevel(); } // Update is called once per frame void Update () { } private void Createlevel () { string[] mapData = ReadLevelText (); int mapX = mapData[0].ToCharArray().Length; int mapY = mapData.Length; Vector3 maxTile = Vector3.zero; Vector3 worldStart = Camera.main.ScreenToWorldPoint(new Vector3 (0, Screen.height)); for(int y = 0; y < mapY; y++) { char[] newTiles = mapData [y].ToCharArray(); for(int x = 0; x < mapX; x++) { maxTile = PlaceTile (newTiles[x].ToString(),x,y,worldStart); } } cameraMovement.SetLimits (new Vector3(maxTile.x + TileSize, maxTile.y - TileSize)); } public Vector3 PlaceTile(string tileType, int x, int y, Vector3 worldStart) { int tileIndex = int.Parse (tileType); TileScript newTile = Instantiate (tilePrefabs[tileIndex]).GetComponent(); *The following line is where it says the error is* newTile.Setup(new Point(x,y), new Vector3 (worldStart.x + (TileSize * x), worldStart.y - (TileSize * y), 0)); return newTile.transform.position; } private string[] ReadLevelText() { TextAsset bindData = Resources.Load ("Level") as TextAsset; string data = bindData.text.Replace(Environment.NewLine,string.Empty); return data.Split('-'); } }

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>