- Home /
Why am I getting an error CS0103?
I'm sorry in advance, I'm relatively new to Unity.
I'm following this tutorial:
http://catlikecoding.com/unity/tutorials/procedural-grid/
and I'm at this state of the code:
using UnityEngine; using System.Collections;
[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]
public class Grid : MonoBehaviour {
public int xSize, ySize;
private Vector3[] vertices;
private void Awake (){
Generate();
}
private void OnDrawGizmos (){
if (vertices == null){
return;
}
Gizmos.color = Color.black;
for (int i = 0; i < vertices.Length; i++){
Gizmos.DrawSphere(vertices[i], 0.1f);
}
}
private void Generate () {
vertices = new Vector3[(xSize + 1) * (ySize + 1)];
for (int y = 0; y <= ySize; y++) {
for (int x = 0; x <= xSize; x++) {
vertices[i] = new Vector3(x, y);
}
}
}
}
On the highlighted part, in the private void Generate I'm getting a compiler error CS0103: 'The name 'i' does not exist in the current context' I'm 99% confident I've followed the tutorial and wrote the code verbatim, but I don't understand what I've done wrong.
Any help would be appreciated.
Answer by Landern · Jun 02, 2015 at 01:24 PM
Confusing, they had the UnityPackage link at the bottom of that post. Also the first for loop is with variable i and y:
vertices = new Vector3[(xSize + 1) * (ySize + 1)];
for (int i = 0, y = 0; y <= ySize; y++) {
for (int x = 0; x <= xSize; x++, i++) {
vertices[i] = new Vector3(x, y);
}
}
in the first for loop there was an i and y variable defined.
Oh god, cheers mate. I was looking so hard and getting a little stressed about it, I'm trying to follow it step by step so when I got that error it confused me. Thanks!
Your answer
Follow this Question
Related Questions
Does a Mesh Vertices/Triangles/etc Have to be Compact 1 Answer
Generate a mesh from randomly positioned points 0 Answers
Terrain Toolkit and Texturing via Code HELP! 1 Answer
Procedurally generated mesh JS - explain the error please 0 Answers
Procedural Mesh Generation - Split Arrays into sections 1 Answer