Random Colors on deck!

So I’ve got a script that shoots “lasers,” with one of six materials on them that are picked randomly. What I’m trying to do is create some sort of preview to what the next random color will be. Sort of like in Tetris, where you may be working on fitting the square and you can see on that side that the “L” is going to be next. Or like the game “Bubble Shoot,” where you can see the color of your next shot.

I have absolutly no idea how to go about tackling this one. Below is my script for random laser shots. If anyone has any ideas or good advice, I’m all ears!

#pragma strict

//Laser random color.

var myMaterials : Material[];  // assign in inspector

 

function Start () 

{

    renderer.material = myMaterials[Random.Range(0, myMaterials.Length)];

}

Hi again. The easiest way I can think of is to parent a cube to the camera and simply assign the material to that cube at the same time you assign it to the laser.

Like this:

    #pragma strict

     

    //Laser random color.

     

    var myMaterials : Material[];  // assign in inspector

    var display : GameObject; 

    var randomMat : int; 

     

    function Start ()

     

    {

        randomMat=Random.Range(0, myMaterials.Length);

        renderer.material = myMaterials[randomMat];

        display.renderer.material = myMaterials[randomMat];

     

    }

Hey, I’m away from my regular computer right now. I like your idea. But wouldn’t parenting the cube to the camera while applying the same script just change the cube the same color as the “laser” that being fired, instead of the color that will be fired next?

That depends on how you implement your laser firing. If you instantiate a prefab when you fire, then yes, it would. If that’s the case simply reverse the process and use the display texture on the laser. I’d need to see the code that fires the laser to tell you the best way to do that.

You can make two random numbers, say randomNumber1 and randomNumber2. So randomNumber1 is the current random number, and randomNumber2 is the next one. When you need another one, randomNumber2 becomes randomNumber1, and you pick a new number for randomNumber2.

–Eric

I’m messing around with the code now. It’s kind of weird. I don’t get any error messages, but I don’t see the display while playing the game. When I stop the game, and go back to edit the display is the color of what ever the color was of the last shot. So if the last shot was orange when I stop, the display will remain orange until I play, and stop, then it updates its cool, but is only visible in while working in edit mode.