// Update is called once per frame
    void Update()
    {
        //從各個文件中抓取當前子彈之數量
        EndAmmo_SMG     = SMGGlobalAmmo.SMGLoadedAmmo;
        EndAmmo_HandGun = GlobalAmmo.HandGunLoadedAmmo;
        EndAmmo_All     = GlobalAmmo.CurrentAmmo;


        //測試卡關自殺按鍵
        if (FPC_Health.health > 0 && PAUSE.pause == false)
        {
            if (Input.GetKeyDown(KeyCode.P))
            {
                while (FPC_Health.health > 0)
                {
                    FPC_Health.Attacked();
                }
            }
        }
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        //主角死亡後停止撥放所有殭屍之音效
        if (FPC_Health.health == 0)
        {
            this.GetComponent <AudioSource>().enabled = false;
            audio.Stop();
        }

        //殭屍死亡
        if (health <= 0f && IsDead == false)
        {
            if (this.gameObject.name == "SceneAllZombie1(Spawn)(Clone)" || this.gameObject.name == "SceneAllZombie2(Spawn)(Clone)")
            {
                //殭屍為一定點方格所產生 當殭屍被擊殺 則尋找此殭屍物件之父物件 並傳送指令至 public void Decrease(int )中 減少殭屍總體數量
                //殭屍總體數量有最大上限 若超過一定數量則不再產生
                this.GetComponentInParent <SceneAllZombieSpawn>().SendMessage("Decrease", 1);
            }


            IsDead = true;
            audio.Stop();
            animator.SetBool("die", true);

            agent.isStopped = true;
            agent.ResetPath();

            go  = false;
            die = true;

            this.GetComponent <CapsuleCollider>().enabled = false;  // This is Important

            audio.PlayOneShot(clip[2]);
        }

        //當殭屍死亡則開始倒數計時 時間歸零則摧毀殭屍物件
        if (die == true && TimeToDestroy > 0)
        {
            TimeToDestroy -= Time.deltaTime;
        }
        if (TimeToDestroy < 0)
        {
            Destroy(this.gameObject);
        }

        //當殭屍被觸發且血量大於0則開始追擊目標
        if (go == true && health > 0)
        {
            agent.SetDestination(target.position);
        }

        //當殭屍開始追擊時撥放觸發音效 run變數為控制音效只撥放一次
        if (go == true && run == false)
        {
            audio.PlayOneShot(clip[1]);
            animator.SetBool("run", true);
            run = true;
        }



        //當攻擊時間歸0則代表攻擊一次 而下次的殭屍攻擊時間為2.65秒(配合動畫之速度)
        if (healthtime < 0)
        {
            healthtime = 2.65f;

            FPC_Health.Attacked();
        }
    }