I’ve been playing with this all day and haven’t been able to make any progress. I have a “laser” that shoots automatically and is one of six random colors. I have a game object with a script that changes into the same 6 colors randomly. The idea is that this game object will act as “preview” of what next laser show will be (like bubble shoot).
As an example: lets say the preview is red. As soon as the preview changes to the next color (lets just say Blue) a red laser will shoot. And since the preview is Blue, we know the next laser will be blue. And so on, and so on, and so on…
The idea is that the changing preview will trigger the firing of the laser, this way I hope I can just change the timing of the preview to control how fast and slow the whole thing works.
// Preview
var myMaterials : Material[];
var delay : float; // seconds between color changes
function Start () {
InvokeRepeating ("ChangeColor", delay, delay);
}
function ChangeColor () {
renderer.material = myMaterials[Random.Range (0, myMaterials.Length)];
}
//Auto Fire Script
var lastFireTime : float;
var fireDelay : float = 3.0f;
var laserBeamPrefab : Transform;
function Update()
{
if(Time.time > lastFireTime + fireDelay)
{
var laserBeam = Instantiate(laserBeamPrefab, gameObject.Find("spawnPoint").transform.position,Quaternion.identity);
laserBeam.rigidbody.AddForce(Vector3.forward * 100);
lastFireTime = Time.time;
}
}