// Update is called once per frame void Update() { currentTime = Time.realtimeSinceStartup; if (LOOK_BACK_STATE) { if (currentTime - lastTime >= LOOK_BACK_TIME) { if (direction.DIRECTION == Direction.DirectionData.LEFT) { direction.DIRECTION = Direction.DirectionData.RIGHT; } else { direction.DIRECTION = Direction.DirectionData.LEFT; } lastTime = Time.realtimeSinceStartup; } } if (currentTime - firingLastTime >= FIRING_INTERVAL) { firing.FiringBullet(); firingLastTime = Time.realtimeSinceStartup; } }
// Update is called once per frame void Update() { currentTime = Time.realtimeSinceStartup; switch (state) { case State.SEARCH: if (currentTime - lastTime >= LOOK_BACK_TIME) { if (direction.DIRECTION == Direction.DirectionData.LEFT) { direction.DIRECTION = Direction.DirectionData.RIGHT; } else { direction.DIRECTION = Direction.DirectionData.LEFT; } lastTime = Time.realtimeSinceStartup; } if (visibility.State) { rays.SetActive(true); state = State.STAND_BY; } break; case State.STAND_BY: if (!visibility.State) { rays.SetActive(false); state = State.SEARCH; } else if (currentTime - lastTime >= FIRING_INTERVAL) { state = State.FIRING; } break; case State.FIRING: firing.FiringBullet(); lastTime = Time.realtimeSinceStartup; state = State.STAND_BY; break; } }