-2

I was creating Voxels, when suddenly, my projectile was... I don't know - removed or something - but it wasn't removed :|

I was creating Voxels and this happened (this is the entire code):

public GameObject Mesh;

float cubeWidth;
float cubeHeight;
float cubeDepth;

public float cubeScale;


void Start()
{
    cubeDepth = transform.localScale.x;
    cubeHeight = transform.localScale.y;
    cubeWidth = transform.localScale.z;

    gameObject.GetComponent<SpriteRenderer>().enabled = false;

    print(Mesh);

    Mesh.gameObject.GetComponent<Transform>().localScale = new Vector3(cubeScale, cubeScale, cubeScale);

    CreateCube();
}

private int Index;

void CreateCube()
{
    for(float x = 0; x < cubeWidth; x+=cubeScale)
    {
        for(float y = 0; x < cubeHeight; x+=cubeScale)
        {
            //print("Starting Y");
            for(float z = 0; x < cubeDepth; x+=cubeScale)
            {
                //print(Mesh + " before creating Vec + " + Index);

                Vector3 vec = transform.position;

                Vector3 newvec = vec + new Vector3(x,y,z);

                GameObject cubes = Instantiate(Mesh, newvec, Quaternion.identity);

                //print(Mesh + " after creating Cubes + " + Index);

                Index += 1;
            }
        }
    }
}

My console says this:

Console says this

Any ideas?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Also i checked guys, this error occurs on Y line (when ending z loop) – ProGrammer Mar 08 '22 at 19:02
  • Please include relevant errors and exception details as text not as image – Ruzihm Mar 08 '22 at 19:53
  • suggests your mesh is empty – BugFinder Mar 08 '22 at 20:04
  • The error is literally telling you what is wrong: `The variable 'Mesh' of 'Voxel' has not been assigned` and `You probably need to assign the 'Mesh' variable of the 'Voxel' script in the Inspector.` ... what exactly do you not understand in that? If you click once on the message it will also show you the stacktrace of where exactly this is happening and if you double click it it will open the file and jump to the according code line in your IDE – derHugo Mar 09 '22 at 08:09
  • derHugo yes i understand the error but i assigned a reference to a Mesh (it's a prefab) – ProGrammer Mar 09 '22 at 12:24
  • oh and error text is: The variable 'Mesh' of 'Voxel' has not been assigned. You probably need to assign the 'Mesh' variable of the 'Voxel' script in the Inspector. – ProGrammer Mar 09 '22 at 12:24

1 Answers1

0

As your errors in the console says. You probably need to assign the GameObject that you're trying to Instantiate. Your variable Mesh isn't assigned to anything in your Voxel object.

dekuShrub
  • 466
  • 4
  • 20