GameObject FindLazer(eSensorDirection dir) { return(this.lazersObjects.Find((GameObject element ) => { sensorLazer maybeObj = element.GetComponentInChildren <sensorLazer>(); if (maybeObj && maybeObj.direction == dir) { return true; } else { return false; } })); }
void NextLazerState() { this.sensorPhaseIndex += 1; this.sensorPhaseIndex = this.sensorPhaseIndex % this.SensorSequence.Count; //Clear all lazers first foreach (GameObject element in lazersObjects) { element.SetActive(false); } foreach (eSensorDirection dir in SensorSequence[this.sensorPhaseIndex]) { GameObject lazerObjectForDir = this.FindLazer(dir); if (lazerObjectForDir) { lazerObjectForDir.SetActive(true); sensorLazer lazer = lazerObjectForDir.GetComponentInChildren <sensorLazer>(); lazer.Reset(); } } }
GameObject CreateLazerOfDirection(float angle, bool startingOn) { GameObject newLazer = Instantiate(this.LazerObject, this.transform.position, Quaternion.identity); newLazer.transform.Rotate(0, 0, angle); newLazer.transform.localScale = new Vector3(1, 10, 0); GameObject newLazerTrack = Instantiate(this.LazerTrackObject, this.transform.position, Quaternion.identity); newLazerTrack.transform.Rotate(0, 0, angle); newLazerTrack.transform.localScale = new Vector3(1, 10, 0); newLazer.SetActive(startingOn); sensorLazer lazerScript = newLazer.GetComponentInChildren <sensorLazer>(); lazerScript.direction = VectorHelper.AngleToDirectionEnum(angle); lazerScript.IsTriggered += this.ShootBulletDirection; lazersObjects.Add(newLazer); return(newLazer); }