Example #1
0
    void Update()
    {
        inRange();

        if (Input.GetKeyDown(KeyCode.R))
        {
            Application.LoadLevel(0);
        }

        if (PlayerContl.getFuel() < 10.0f)
        {
            tutContrl.AddFuel();
        }

        if (Camera.main.transform.position.y - _player.transform.position.y < -6.5f && Camera.main.transform.position.y - _player.transform.position.y > -10)
        {
            if (!endBeforeFinish)
            {
                Scoring _endScore = Instantiate(endScore, transform.position, Quaternion.identity) as Scoring;
                _endScore.setScore(totalPoints, false);
                cam.disable();
                _hud.count      = false;
                endBeforeFinish = true;
            }
        }

        Timer         += Time.deltaTime;
        TimerCoolDown += Time.deltaTime;

        if (Mathf.Ceil((mapGenerator.mapHeight - _player.transform.position.y) / (mapGenerator.mapHeight / maxLayers)) != lastLayer)
        {
            {
                if (lastLayer < 4)
                {
                    SubQuest _subQuest = Instantiate(subQuest, transform.position, Quaternion.identity) as SubQuest;
                    currentLayer = Mathf.Ceil((mapGenerator.mapHeight - _player.transform.position.y) / (mapGenerator.mapHeight / maxLayers));
                    lastLayer    = currentLayer;

                    _subQuest.setInfo(_player.transform, (int)currentLayer, maxLayers, mapGenerator.mapHeight);

                    currentSubquest = _subQuest;

                    //start running camera
                    if (lastLayer == 1)
                    {
                        cam.enable();
                    }

                    if (lastLayer == 3)
                    {
                        tutContrl.BombUsedCheck();
                    }
                    if (lastLayer == 2)
                    {
                        tutContrl.MisiionUsedCheck();
                    }
                }
                else
                {
                    if (!endStarted)
                    {
                        //flipping around
                        _player.GetComponent <PlayerController> ().negativeGravity();

                        //rotate the camera
                        endAnimation = true;

                        _hud.count = false;
                        endStarted = true;
                        //gameOver();
                    }
                }
            }
        }

        if (endAnimation)
        {
            if (cam.transform.eulerAngles.z > 180 || Camera.main.transform.eulerAngles.z == 0)
            {
                cam.transform.Rotate(Vector3.back * 100 * Time.deltaTime);
            }
            else
            {
                cam.GetComponent <GameCamera>().disable();

                TileScore bonusScore = Instantiate(tileScore, _player.transform.position, Quaternion.identity) as TileScore;
                bonusScore.setScore(20000);

                Scoring _endScore = Instantiate(endScore, transform.position, Quaternion.identity) as Scoring;
                _endScore.setScore(totalPoints, true);

                endAnimation = false;
            }
        }


        if (multiplierTimer < 0)
        {
            multiplierTimer = 0;
            scoreMultiplier = 1;

            buttonStateUpdate();
        }
        else if (multiplierTimer > 0)
        {
            multiplierTimer -= Time.deltaTime;
        }



        if (shake_intensity > 0)
        {
            Camera.main.transform.position = originPosition + Random.insideUnitSphere * shake_intensity;
            Camera.main.transform.position = new Vector3(Camera.main.transform.position.x, cam.transform.position.y, Camera.main.transform.position.z);
            Camera.main.transform.rotation = new Quaternion(
                originRotation.x + Random.Range(-shake_intensity, shake_intensity) * .2f,
                originRotation.y + Random.Range(-shake_intensity, shake_intensity) * .2f,
                originRotation.z + Random.Range(-shake_intensity, shake_intensity) * .2f,
                originRotation.w + Random.Range(-shake_intensity, shake_intensity) * .2f);
            shake_intensity -= shake_decay;
        }
        else if (!endAnimation)
        {
            Camera.main.transform.rotation = cam.transform.rotation;
        }
        //Debug.Log ("camPos : " + Camera.main.transform.position);
        //Debug.Log ("camObj : " + cam.transform.position);
    }