示例#1
0
    // Update is called once per frame
    void Update()
    {
        //Escape Menu
#if UNITY_EDITOR
        bool escapeMenuKeyPressed = Input.GetKeyDown(KeyCode.Escape);
#else
        bool escapeMenuKeyPressed = GameManager.Instance.enableSeebright ? SBRemote.GetButton(SBRemote.BUTTON_BACK) : Input.GetKeyDown(KeyCode.Escape);
#endif
        if (escapeMenuKeyPressed && !isClone)
        {
            if (!_escapeMenu.currentlyActive)
            {
                _escapeMenu.display();
            }
        }
        if (_escapeMenu.currentlyActive)
        {
            return;
        }

#if !UNITY_IPHONE
        Screen.lockCursor = true;
#endif

        //Invulnerability
        if (_invulnerable)
        {
            renderer.enabled = Mathf.Sin(Time.time * 50.0f) > 0;
        }
        if (Time.time > _invulnerabilityCooldown + RESPAWN_COOLDOWN)
        {
            renderer.enabled = true;
            _invulnerable    = false;
        }
        if (_transitioning && currentLevel.SpawnLane != null)
        {
            //if transitioning levels and clone is active, destroy clone
            if (isClone)
            {
                GameManager.Instance.removeShip(this);
                Destroy(gameObject);
            }
            setCamera();
            if (_goingDownLane)
            {
                gameObject.transform.position = Vector3.Lerp(_startPos, _endOfLane, (Time.time - _startTransTime) / (PLAYER_LEVEL_TRANSITION_TIME * 0.25f));
                if (gameObject.transform.position == _endOfLane)
                {
                    _goingDownLane = false;
                }
            }
            else
            {
                gameObject.transform.position = Vector3.Lerp(_endOfLane, currentLevel.SpawnLane.Front, (Time.time - _startTransTime) / (PLAYER_LEVEL_TRANSITION_TIME * 0.75f));
            }
            gameObject.transform.Rotate(new Vector3(1, 0, 0), 360.0f * (Time.time - _startTransTime) / PLAYER_LEVEL_TRANSITION_TIME);

            //Level Transition
            if (gameObject.transform.position == currentLevel.SpawnLane.Front &&
                CameraController.currentCamera.gameObject.transform.position == currentLevel.cameraPosition.transform.position)
            {
                if (!_flashbang.running)
                {
                    _flashbang.init(FLASHBANG_TIME);
                }
                if ((Time.time - _startTransTime) / (PLAYER_LEVEL_TRANSITION_TIME + FLASHBANG_TIME / 2.0f) >= 1.0f)
                {
                    CameraController.currentCamera.setRetroShader(false);
                }
                if (_flashbang.manualUpdate())
                {
                    return;
                }
                CameraController.currentCamera.setRetroShader(false);
                _transitioning = false;
                Destroy(_previousLevel);
                if (currentLevel.SpawnLane != null)
                {
                    currentPlane = currentLevel.lanes.IndexOf(currentLevel.SpawnLane);
                }
                else
                {
                    currentPlane = 0;
                }
            }
            return;
        }
        if (currentLevel == null || currentLevel.lanes == null)
        {
            return;
        }

        //This is a preprocess directive, exclusively used with Unity Editor
        //#yoyoloop
#if UNITY_EDITOR
        if (Input.GetKeyDown(KeyCode.Space))   // testing purposes
        {
            ActivateClone();
            ActivateMulti();
            ActivateRapid();
        }

        if (Input.GetKeyDown(KeyCode.F1))
        {
            _invulnerable            = !_invulnerable;
            _invulnerabilityCooldown = (_invulnerable) ? float.MaxValue : 0;
            GUIManager.Instance.addGUIItem(new GUIItem(Screen.width / 2, Screen.height / 2, "God Mode : " + _invulnerable.ToString(), GUIManager.Instance.defaultStyle, 4));
        }
#endif

        if (!_alive)
        {
            return;
        }

        if (!isClone)
        {
            handleMovement();
            if (_clone)
            {
                _clone.handleMovement();
            }
        }

        // shoot
        if (_numShots < 0)
        {
            _numShots = 0;
        }

        int maxMultiShots = MAX_SHOTS;
        if (isMultiActivated)
        {
            maxMultiShots = MAX_SHOTS * 3 - 2; // -2 for +3 shots from multi shot so it fires at 12 max (<13)
        }
#if UNITY_IPHONE && !UNITY_EDITOR
        bool triggerPressed = (GameManager.Instance.enableSeebright) ? SBRemote.GetButton(SBRemote.BUTTON_TRIGGER) : GameManager.Instance.TriggerPressed;
#elif UNITY_IPHONE && UNITY_EDITOR
        bool triggerPressed = (GameManager.Instance.enableSeebright) ? Input.GetMouseButton(0) : GameManager.Instance.TriggerPressed;
#else
        bool triggerPressed = Input.GetMouseButton(0);
#endif

        if (triggerPressed && _reload < 0 && _numShots < maxMultiShots)
        {
            Shoot();
            _reload = DELAY_NEXT_SHOT;
            if (isRapidActivated)
            {
                _reload /= 2.0f;
            }
        }

        // reload
        _reload -= Time.deltaTime;

        // powerup timers
        if (_rapidTime < 0)
        {
            isRapidActivated = false;
        }
        else
        {
            _rapidTime -= Time.deltaTime;
        }

        if (_multiTime < 0)
        {
            isMultiActivated = false;
        }
        else
        {
            _multiTime -= Time.deltaTime;
        }

        if (_clone == null)
        {
            isCloneActivated = false;
        }
    }