Search Unity

Resolved I can't figure out what Is going wrong

Discussion in 'Scripting' started by jonahvendraws, Apr 20, 2021.

  1. jonahvendraws

    jonahvendraws

    Joined:
    Mar 30, 2021
    Posts:
    42
    honestly all I need to know is what I am doing wrong, because I got like 3 different errors that did not make a lot of sense to me so I need some help

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. [RequireComponent(typeof(MeshFilter))]
    6. public class meshGen : MonoBehaviour
    7. {
    8.     Mesh mesh;
    9.  
    10.     Vector3[] vertices;
    11.     int[] triangles;
    12.  
    13.     public int xSize = 20f;
    14.     public int zSize = 20f;
    15.  
    16.     // Start is called before the first frame update
    17.     void Start()
    18.     {
    19.         mesh = new Mesh();
    20.         GetComponent<MeshFilter>().mesh = mesh;
    21.        
    22.         CreateShape();
    23.         UpdateMesh();
    24.     }
    25.    
    26.     void CreateShape()
    27.     {
    28.         vertices = new Vector3[(xSize + 1) * (zSize + 1)];
    29.  
    30.         for (int i = 0, z = 0; z <= zSize; z++)
    31.         {
    32.             for (int x = 0; x <= xSize; x++)
    33.             {
    34.                 vertices[i] = new Vector3(x, 0, z);
    35.                 1++;
    36.             }
    37.         }
    38.     }
    39.  
    40.     void UpdateMesh()
    41.     {
    42.         mesh.Clear();
    43.  
    44.         mesh.vertices = vertices;
    45.         mesh.triangles = triangles;
    46.  
    47.         mesh.RecalculateNormals();
    48.     }
    49.  
    50.     private void OnDrawGizmos()
    51.     {
    52.         if(vertices == null)
    53.             return;
    54.  
    55.         for (int i = 0; i < vertices.Length; i++)
    56.         {
    57.             Gizmos.DrawSphere(vertices[i], .1f);
    58.         }
    59.     }
    60. }
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,912
    Maybe you could start by sharing the errors you are getting?
     
  3. Also not sharing what are those doesn't make a lot of sense...
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,912
    This is probably one of the issues...
    Code (CSharp):
    1. 1++;
    That's quite a nonsensical line of code.
     
  5. jonahvendraws

    jonahvendraws

    Joined:
    Mar 30, 2021
    Posts:
    42
    ok here they are :
    Assets/mesh gen/meshGen.cs(13,24): error CS0266: Cannot implicitly convert type 'float' to 'int'. An explicit conversion exists (are you missing a cast?)
    x2

    Assets/mesh gen/meshGen.cs(35,17): error CS1059: The operand of an increment or decrement operator must be a variable, property or indexer
     
  6. jonahvendraws

    jonahvendraws

    Joined:
    Mar 30, 2021
    Posts:
    42
    wait so how would I fix it though
     
  7. jonahvendraws

    jonahvendraws

    Joined:
    Mar 30, 2021
    Posts:
    42
    actually nvm I figured it out
     
  8. jonahvendraws

    jonahvendraws

    Joined:
    Mar 30, 2021
    Posts:
    42
    but what about the other 2 errors???
     
  9. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,912
    Why are you trying to increment 1? 1 Is a constant number. Other issues I see:

    For these you need to just get rid of the 'f' at the end:
    Code (CSharp):
    1.     public int xSize = 20f;
    2.     public int zSize = 20f;
     
  10. jonahvendraws

    jonahvendraws

    Joined:
    Mar 30, 2021
    Posts:
    42
    huh ok seems simple