#Tech Help Required! My unity is crashing possibly due to the while loop. But no solution is working.

1 messages · Page 1 of 1 (latest)

nimble spadeBOT
#

Use codeblocks to send code in a message!

To make a codeblock, surround your code with ```
To use C# syntax highlighting add cs after the three back ticks.

For example:
```cs
Console.WriteLine("Hello World");
```

Produces:

Console.WriteLine("Hello World");

To send lengthy code, paste it into https://paste.myst.rs/ and send the link of the paste into chat.

vital zinc
#

Why on earth are you sending your code as a docfx file

sterile shadow
#

And why the heck would you choose to send a script as a Word document?

vital zinc
#

Jynx var

sterile shadow
#

Great minds think alike or something LUL

fleet summit
#

@vital zinc @sterile shadow Sorry bro. It was showing exceeding word limit... Anyways, please look into the problem and try to help... It is a very important project I have to make.

vital zinc
#

Send your code properly

fleet summit
#

Yes doing

#

This is my code. Kindly try to review it

#

It would be a great help

sterile shadow
#

Okay, so basically you are trying to assign each cube a random material, but make sure each material only appears 3 times. Right?

#

Because in that case, all you really need to do is create a pool (read: List<Material>) that contains each available material 3 times.
Then you iterate over all cubes and choose a random entry from the list to assign to the cube, removing that material from the pool in the process.

fleet summit
#

no, basically my aim is that all the materials get assigned equally

#

rest you understood correctly

sterile shadow
#

Equally?
Then why did you hard-code 3 everywhere? (Which is a bad idea btw. Don't use magic numbers)

fleet summit
#

so what should i do?

sterile shadow
#

Instead of using 3 everywhere, divide the number of cubes through the number of different materials, and use that.

#

The rest of the solution I described above still applies, if done like this.

fleet summit
#

will this work without creating a list and instead just replacing the < 3 with < (number of small cubes / number of materials)?

sterile shadow
#

No

fleet summit
#

Oh, understood!

#

Thanks @sterile shadow