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

how do i fix this error

$
0
0
I am following this tut and I cant figure out were this error is coming from. hears the tut http://studentgamedev.blogspot.no/2013/08/VoxelTutP2.html the error NullReferenceException UnityEngine.Mesh.Clear () (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/Graphics.cs:609) PolygonGenerator.UpdateMesh () (at Assets/PolygonGenerator.cs:84) PolygonGenerator.Start () (at Assets/PolygonGenerator.cs:33) ![alt text][1] hears the script using UnityEngine; using System.Collections.Generic; public class PolygonGenerator : MonoBehaviour { // This first list contains every vertex of the mesh that we are going to render public List newVertices = new List(); // The triangles tell Unity how to build each section of the mesh joining // the vertices public List newTriangles = new List(); // The UV list is unimportant right now but it tells Unity how the texture is // aligned on each polygon public List newUV = new List(); // A mesh is made up of the vertices, triangles and UVs we are going to define, // after we make them up we'll save them as this mesh private Mesh mesh; private float tUnit = 0.25f; private Vector2 tStone = new Vector2 (0, 0); private Vector2 tGrass = new Vector2 (0, 1); private int squareCount; public byte[,] blocks; void Start () { GenTerrain(); BuildMesh(); UpdateMesh(); mesh = GetComponent ().mesh; float x = transform.position.x; float y = transform.position.y; float z = transform.position.z; newVertices.Add( new Vector3 (x , y , z )); newVertices.Add( new Vector3 (x + 1 , y , z )); newVertices.Add( new Vector3 (x + 1 , y-1 , z )); newVertices.Add( new Vector3 (x , y-1 , z )); newTriangles.Add(0); newTriangles.Add(1); newTriangles.Add(3); newTriangles.Add(1); newTriangles.Add(2); newTriangles.Add(3); newUV.Add(new Vector2 (tUnit * tStone.x, tUnit * tStone.y + tUnit)); newUV.Add(new Vector2 (tUnit * tStone.x + tUnit, tUnit * tStone.y + tUnit)); newUV.Add(new Vector2 (tUnit * tStone.x + tUnit, tUnit * tStone.y)); newUV.Add(new Vector2 (tUnit * tStone.x, tUnit * tStone.y)); } void GenSquare(int x, int y, Vector2 texture){ newVertices.Add( new Vector3 (x , y , 0 )); newVertices.Add( new Vector3 (x + 1 , y , 0 )); newVertices.Add( new Vector3 (x + 1 , y-1 , 0 )); newVertices.Add( new Vector3 (x , y-1 , 0 )); newTriangles.Add(squareCount*4); newTriangles.Add((squareCount*4)+1); newTriangles.Add((squareCount*4)+3); newTriangles.Add((squareCount*4)+1); newTriangles.Add((squareCount*4)+2); newTriangles.Add((squareCount*4)+3); newUV.Add(new Vector2 (tUnit * texture.x, tUnit * texture.y + tUnit)); newUV.Add(new Vector2 (tUnit*texture.x+tUnit, tUnit*texture.y+tUnit)); newUV.Add(new Vector2 (tUnit * texture.x + tUnit, tUnit * texture.y)); newUV.Add(new Vector2 (tUnit * texture.x, tUnit * texture.y)); squareCount++; } void UpdateMesh () { mesh.Clear (); mesh.vertices = newVertices.ToArray(); mesh.triangles = newTriangles.ToArray(); mesh.uv = newUV.ToArray(); mesh.Optimize (); mesh.RecalculateNormals (); squareCount=0; newVertices.Clear(); newTriangles.Clear(); newUV.Clear(); } void GenTerrain(){ blocks=new byte[10,10]; for(int px=0;px

Viewing all articles
Browse latest Browse all 7934

Trending Articles



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