Ejemplo n.º 1
0
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag("Gold") && playerHealth > 0)
        {
            dust         += 5;
            playerHealth += 5;
            Destroy(collision.gameObject);
            uIBarControl.SetHealth(playerHealth);
            healthbarongame.SetHealth(playerHealth);
        }
        if (collision.gameObject.CompareTag("Green") && playerHealth > 0)
        {
            dust         += 5;
            playerHealth += 5;
            Destroy(collision.gameObject);
            uIBarControl.SetHealth(playerHealth);
            healthbarongame.SetHealth(playerHealth);
        }
        if (collision.gameObject.CompareTag("White") && playerHealth > 0)
        {
            dust         += 5;
            playerHealth += 5;
            Destroy(collision.gameObject);
            uIBarControl.SetHealth(playerHealth);
            healthbarongame.SetHealth(playerHealth);
        }
        if (collision.gameObject.CompareTag("Blue") && playerHealth > 0)
        {
            dust         += 5;
            playerHealth += 5;
            Destroy(collision.gameObject);
            uIBarControl.SetHealth(playerHealth);
            healthbarongame.SetHealth(playerHealth);
        }

        //else if (collision.gameObject.CompareTag("Item"))
        //{
        //    collision.gameObject.GetComponent<ItemPickup>().PickUp();
        //}
    }
Ejemplo n.º 2
0
    public virtual void GetHit(float Damage)
    {
        //被攻擊後歸零下一次怪物攻擊時間
        if (enemyController != null)
        {
            enemyController.attackCD = 0;
        }
        //播放受擊動畫
        animator.SetTrigger("GetHit");
        //朝面對的反方向後退
        if (faceDirection != null)
        {
            rigidbody.velocity = -faceDirection.forward * bounceForce;
        }
        //取消追蹤玩家凸顯後退效果應該沒用
        if (navMeshAgent != null)
        {
            navMeshAgent.enabled = false;
        }
        //毒的受擊次數減少
        if (beAttackMin > 0)
        {
            beAttackMin--;
        }
        //受擊音效
        if (enumAttack != EnumAttack.count)
        {
            switch (enumAttack)
            {
            case EnumAttack.wind:
            {
                audioSource.PlayOneShot(windHitSFX);
                break;
            }

            //暫時沒用
            //case EnumAttack.poison:
            //    {
            //        audioSource.PlayOneShot(poisonHitSFX);
            //        break;
            //    }
            case EnumAttack.fireTornado:
            {
                audioSource.PlayOneShot(tornadoHitSFX);
                break;
            }

            default:
            {
                //如果被風、讀、火龍捲打到就跳過
                break;
            }
            }
        }
        //誰被打到
        Debug.Log(transform.name);
        //生成特效
        GameObject FX = Instantiate(getHitEffect[0], transform.position + Vector3.up * 0.8f, transform.rotation);

        //一秒後刪除特效
        Destroy(FX, 1);
        //怪物血量減少
        Hp -= Damage;
        //實際血量顯示在UI
        healthBarOnGame.SetHealth(Hp);
        //跟上面重複被擊退應該沒用
        //rigidbody.velocity = -gameObject.transform.forward * pushforce;
        //如果怪物死亡
        if (Hp <= 0)
        {
            MonsterDead();
            //避免一直跳進來
            beAttackMin = 0;
        }
    }
Ejemplo n.º 3
0
    void Update()
    {
        lastFireTime += Time.deltaTime;
        Movement.Set(0, 0, 0);
        //攻速&普攻按鍵
        attackTime += Time.deltaTime;
        if (attackTime >= attackSpeed &&
            !gameMenu.anyWindow[0].activeSelf && !gameMenu.anyWindow[2].activeSelf && !gameMenu.anyWindow[4].activeSelf && !gameMenu.anyWindow[5].activeSelf && !gameMenu.anyWindow[6].activeSelf &&
            !playerFaceDirection.isMagicAttack && getHitEffect.playerHealth > 0 && !isRoll)
        {
            if (Input.GetMouseButtonDown(0))
            {
                if (EventSystem.current.IsPointerOverGameObject())
                {
                    return;
                }
                Attack();
                attackTime = 0;//另外一種計時方式
            }
            if (Input.GetMouseButtonDown(1) && attackTime >= attackSpikeSpeed)
            {
                if (EventSystem.current.IsPointerOverGameObject())
                {
                    return;
                }
                Attack();
                attackTime = 0;//另外一種計時方式
            }
        }
        //開關玩家血條
        if (Input.GetKeyDown(KeyCode.P))
        {
            playerOptions.SetPlayerHealthActive();
        }
        //開關怪物血條
        if (Input.GetKeyDown(KeyCode.O))
        {
            playerOptions.SetMonsterHealthActive();
        }
        //開關背包介面
        if (Input.GetKeyDown(KeyCode.B) && !gameMenu.anyWindow[0].activeSelf)
        {
            backPackUI.SetActive(!backPackUI.activeSelf);
        }
        if (Input.GetKeyDown(KeyCode.K) && !gameMenu.anyWindow[0].activeSelf)
        {
            skillUI.SetActive(!skillUI.activeSelf);
        }
        if (Input.GetKeyDown(KeyCode.Tab))
        {
            miniMap.SetActive(!miniMap.activeSelf);
        }

        //卸下所有裝備欄裡的裝備
        if (Input.GetKeyDown(KeyCode.U))
        {
            equipmentManager.UnequipAll();
        }
        #region 存檔功能
        if (Input.GetKeyDown(KeyCode.Z))
        {
            Debug.Log("存檔中");
            SaveSystem.SavePlayer(getHitEffect, transform);
        }
        if (Input.GetKeyDown(KeyCode.X))
        {
            Debug.Log("回復存檔");
            PlayerData data = SaveSystem.LoadPlayer();
            getHitEffect.playerHealth = data.Playerhealth;
            uIBarControl.SetHealth(data.Playerhealth);
            Vector3 SavePosition;
            SavePosition.x     = data.position[0];
            SavePosition.y     = data.position[1];
            SavePosition.z     = data.position[2];
            transform.position = SavePosition;
            Debug.Log(SavePosition);
            healthbarongame.SetHealth(data.Playerhealth);//人物身上的血條
        }
        #endregion
        //翻滾
        if (Input.GetKeyDown(KeyCode.Space) && getHitEffect.playerHealth > 0 /* && !animator.GetBool("IsAttack")*/)
        {
            if (lastFireTime > fireRate)
            {
                Roll();
                lastFireTime = 0;
            }
        }
        if (isInvincible)
        {
            rollTime += Time.deltaTime;
        }
        //無敵時間超過上限取消無敵狀態
        if (rollTime > rollTimeLimit)
        {
            isInvincible         = false;
            rollTime             = 0;
            rigidbody.velocity   = Vector3.zero;
            collider.isTrigger   = false;
            rigidbody.useGravity = true;
            rayMask = wall & monster;
            isRoll  = false;
        }

        if (stamina < staminaLimit)
        {
            stamina += Time.deltaTime * 10;
            uIBarControl.SetStamina(stamina);
        }
        else
        {
            stamina = staminaLimit;
            uIBarControl.SetStamina(stamina);
        }

        if (Input.GetKeyDown(KeyCode.N))//傳送到指定地點 &場景重置
        {
            transform.position = new Vector3(-6.31f, 0, 6.08f);
            Application.LoadLevel(Application.loadedLevel);
        }
    }