Random mesh chooser + log question


I am trying to let the computer pick 1 (random) mesh 1 to 4, once the PC has chosen which mesh it’ll be the feedback will just be a color (renderer.material.color = Color.purle;). If the player hits the correct mesh it’ll +1 random mesh, if it’s the wrong one game over.

For example;

function OnMouseDown () {
renderer.material.color = Color.‘colourwhattheblockneedstobe’;

however the computer needs to log all the random meshes (until game over) because if you got 1 correct you have to start over so it’ll become harder and harder over time.
(never worked with logging stuff the player has clicked)

But I am completely stuck right now. If someone could help me / explain or has a tutorial lookalike about this it would really help me out, a lot!

Thanks in advance.

If you have them all childed to something, you can use GetChild(0 to 3) to look them up. Ex:

transform.getChild(2).renderer.material.color=Color.red; // turns 3rd one red

GetChild is “slow,” but only in the the sense that you don’t want to to it more then 20 or 30 times per frame.

If you want a sequence of them, can make an array of 0-3’s and go through it:

public var S1: int[]; // drag in 0-3's. ex: 2,0,1,2,1,3,0
var current : int = 0;
// current says if you are on the 2, or the 0, or the 1 ...
// will be from 0 to 5. current=5 means you are on the "3"

So, to flash them all, you might use:

// turn off the one we are on:
var i : int = S1[current]; // gets the 0-3 from the list

// go to next one:
if(current>S1.Length) current=0; // wrap-around

// turn on next one:

Just in Update, that would flash them madly, in that order (the dot-Length might be wrong – I don’t use javaScript.)

The part where the user picks one is a lot more work, but, say they just clicked on Transform TC. Could check for the correct one with something like: i=S1[current]; correctOne = transform.getChild(i); if(TC==correctOne).