Hi Everyone,
I hope I’m using terms that make sense. I’m a veteran 3D artist learning programming for Unity. Basically what I’ve got is an object that randomly selects an object from an array and instances it. That part works perfect, the next step I want is to give each object in the array a frequency value so I can make that object more or less likely to be selected.
Ideally in the inspector it would look something like this:
- Element 0 “gameObjectA”
- Element 0 Frequency “0.25”
- Element 1 “gameObjectB”
- Element 1 Frequency “0.40”
- Element 2 “gameObjectC”
- Element 2 Frequency “0.05”
- Element 3 “gameObjectD”
- Element 3 Frequency “0.30”
In the above example, gameObjectA would have a 25% chance of being selected for instancing while gameObjectC would only have a 5% chance, etc.
I’m really not sure where to start on this one. It needs to be something that I can easily expand as I’m not really sure how many elements I’ll need in the end. I’m hoping what I’m looking for is just an expansion of the array function and I’m just using the wrong terms in my search. I really just need a push in the right direction.
By the way, I’m working in JavaScript. Please don’t reply telling me to do this in C#. I realize and appreciate C# is generally considered a more robust language but what I’m working on is using JavaScript.
Thanks for any help.