x


Populate classes randomly and store them into array.

Hello,

I have a "Character" script and inside that, I have a "Attributes" class. What I want to do is to create a random number of characters, add their attributes (I have already create the algorithm for this), store those characters into an array and finally when I chose a character from a menu add him/her into the World by creating a new GameObject.

I'm not looking for a working code. I just want to hear different opinions and then decide what is the best way to achieve such thing.

Thank you for your time.

more ▼

asked Feb 11 '12 at 12:10 AM

kirkd10 gravatar image

kirkd10
1 1 2

C# or Javascript?

Feb 11 '12 at 12:23 AM DaveA

I'm programming in Javascript. But it doesn't really matter. What I really want to find out is the method of doing this.

Feb 11 '12 at 12:28 AM kirkd10

You can add a random number of elements to a list that holds a struct of whatever attributes you need. When you populate the list you can access the constructor of the struct and assign those attributes random values. Then when you actually add the character to the game you can copy the attributes from the list to the character's component.

It's crude, but should work.

Feb 12 '12 at 03:55 AM asafsitner
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5060
x3446
x336

asked: Feb 11 '12 at 12:10 AM

Seen: 489 times

Last Updated: Feb 12 '12 at 03:55 AM