Example #1
0
    // Update is called once per frame
    void Update()
    {
        //bad
        if(mHealthUI == null) {
            if(UIModalManager.instance != null) {
                mHealthUI = UIModalManager.instance.transform.parent.GetComponentInChildren<UIHealth>();
                if(mHealthUI != null) {
                    mHealthUI.Attach(transform);
                    mHealthUI.gameObject.SetActive(mCurHealth < maxHealth);
                }
            }
        }

        switch(mCurState) {
            case State.None:
                break;

            case State.RegenWait:
                mCurTime += Time.deltaTime;
                if(mCurTime >= regenDelay) {
                    SetState(State.Regen);
                }
                break;

            case State.Regen:
                mCurHealth += (idleRegen ? regenRateIdle : regenRate) * Time.deltaTime;
                if(mCurHealth >= maxHealth) {
                    mCurHealth = maxHealth;
                    SetState(State.None);
                }
                else {
                    if(mTiler != null) {
                        mTiler.numTiles = minTileRes + (maxTileRes - minTileRes) * (mCurHealth / maxHealth);
                    }

                    ApplyHealthText();
                }
                break;

            case State.Dead:
                if(mTiler != null) {
                    mCurTime += Time.deltaTime;
                    if(mCurTime < minTileDeathDelay) {
                        mTiler.numTiles = minTileRes + (mCurTime / minTileDeathDelay) * (minTileDeathRes - minTileRes);
                    }
                    else {
                        mTiler.numTiles = minTileDeathRes;
                        mTiler = null;
                    }
                }
                break;
        }
    }
Example #2
0
    private void SetState(State newState)
    {
        //undo previous stuff

        //new stuff
        mCurState = newState;

        if(mCurState == State.None) {
            if(mTiler != null) {
                mTiler.enabled = false;
                mTiler = null;
            }
        }
        else if(mTiler == null) {
            CameraController cc = CameraController.instance;
            if(cc != null) {
                mTiler = cc.mainCamera.GetComponent<M8.ImageEffects.Tile>();
            }
        }

        if(mHealthUI != null) {
            mHealthUI.gameObject.SetActive(mCurHealth < maxHealth);
        }

        switch(newState) {
            case State.RegenWait:
                if(mTiler != null) {
                    mTiler.numTiles = minTileRes + (maxTileRes - minTileRes) * (mCurHealth / maxHealth);
                }

                mCurTime = 0.0f;

                StopAllCoroutines();
                StartCoroutine(HurtMe());
                break;

            case State.Regen:
                break;

            case State.Dead:
                StopAllCoroutines();

                if(mTiler != null) {
                    mTiler.enabled = true;
                    mTiler.numTiles = minTileRes;
                }

                mCurTime = 0.0f;
                break;
        }
    }