IEnumerator CheckOccupy() { while (true) { yield return(new WaitForSeconds(0.5f)); if ((transform.position - Camera.main.transform.position).sqrMagnitude < 6 * radius * radius) { projector.enabled = true; } else { projector.enabled = false; } occupy = GetOccupy(); } }
void Update() { switch (occupy) { case OccupyStat.Blue: progress = Mathf.MoveTowards(progress, 1, Time.deltaTime / occupyTime); break; case OccupyStat.Red: progress = Mathf.MoveTowards(progress, -1, Time.deltaTime / occupyTime); break; case OccupyStat.Conflict: //no change break; case OccupyStat.None: if (progress < 0.999 && progress > -0.999) { switch (occupied) { case OccupyStat.Blue: progress = Mathf.MoveTowards(progress, 1, Time.deltaTime / occupyTime); break; case OccupyStat.Red: progress = Mathf.MoveTowards(progress, -1, Time.deltaTime / occupyTime); break; case OccupyStat.None: progress = Mathf.MoveTowards(progress, 0, Time.deltaTime / occupyTime); break; } } break; } switch (occupied) { case OccupyStat.Blue: if (progress <= 0) { occupied = OccupyStat.None; centerBeam.sharedMaterial = neutralMat; centerBall.sharedMaterial = neutralMat; mark.mainColor = new Color(1, 1, 1, 1); } break; case OccupyStat.Red: if (progress >= 0) { occupied = OccupyStat.None; centerBeam.sharedMaterial = neutralMat; centerBall.sharedMaterial = neutralMat; mark.mainColor = new Color(1, 1, 1, 1); } break; case OccupyStat.None: if (progress > 0.999) { occupied = OccupyStat.Blue; centerBeam.sharedMaterial = blueMat; centerBall.sharedMaterial = blueMat; mark.mainColor = new Color(0, 0.5f, 1, 1); } else if (progress < -0.999) { occupied = OccupyStat.Red; centerBeam.sharedMaterial = redMat; centerBall.sharedMaterial = redMat; mark.mainColor = new Color(1, 0, 0, 1); } break; } if (progress > 0) { beamRed.localScale = new Vector3(1, 0, 1); beamBlue.localScale = new Vector3(1, progress * beamNeutral.localScale.y, 1); } else { beamRed.localScale = new Vector3(1, -progress * beamNeutral.localScale.y, 1); beamBlue.localScale = new Vector3(1, 0, 1); } }