x


random array variable

    public GameObject rndBall;

GameObject[] NBall = new USprefsPack.GameObject [6];
    BallList[0] = USprefsPack.greenBall;
    BallList[1] = USprefsPack.blueBall;
    BallList[2] = USprefsPack.redBall;
    BallList[3] = USprefsPack.whiteBall;
    BallList[4] = USprefsPack.yellowBall;
    BallList[5] = USprefsPack.purpleBall;

The question is: How to appropriate a variable rndBall any of values in array NBall

more ▼

asked Jan 06 '10 at 04:57 PM

Blitz gravatar image

Blitz
3 1 1 2

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Are you intending to put the various colored balls into NBall, or BallList (which isn't defined in your snippet)?

Here's the simplest way to do it.

rndBall = NBall[Random.Range(0, NBall.Length-1)];

See also: http://answers.unity3d.com/questions/203/how-to-generate-a-random-number-inside-unity

more ▼

answered Jan 06 '10 at 05:05 PM

Ehren gravatar image

Ehren
4.2k 35 43 77

Thanks. i forgot to replace BallList with NBall when i modified the script

Jan 06 '10 at 08:57 PM Blitz

No problem. Glad I could help!

Jan 06 '10 at 09:35 PM Ehren
(comments are locked)
10|3000 characters needed characters left
Your answer
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:

x5097

asked: Jan 06 '10 at 04:57 PM

Seen: 2065 times

Last Updated: Jan 06 '10 at 04:57 PM