Beispiel #1
0
 void DelegateSetUp()
 {
     npcDelegate += attackStateChangeCodeFunction;
     npcDelegate += npcColorSetting;
     npcDelegate += movementStateCheck;
     npcDelegate += NpcDead;
     npcDelegate += npcmove.delegateUpdate;
     npcDelegate += playermove.delegateUpdate;
 }
 void DelegateSetUp()
 {
     npcDelegate += attackStateChangeCodeFunction;
     //npcDelegate += npcColorSetting;
     npcDelegate += ControlAniSetting;
     npcDelegate += movementStateCheck;
     npcDelegate += movementAnimationSetting;
     npcDelegate += NpcDead;
     npcDelegate += movementSound;
     if (npcmove != null)
     {
         npcDelegate += npcmove.delegateUpdate;
     }
     if (playermove != null)
     {
         npcDelegate += playermove.delegateUpdate;
     }
 }
Beispiel #3
0
    void NpcDead()   //do once
    {
        #region npc死亡時做的程式
        if (npcclass.liveStateP == npcClass.liveState.dead && npcclass.TypeP == npcClass.Type.normal) //當死亡時
        {
            if (!IsAlreadyStartDeadFunction)                                                          //當死亡時只做一次
            {
                IsAlreadyStartDeadFunction = true;

                spawnHPParticle(10);
                //GetComponent<npcMove>().enabled = false;
                npcclass.CastAniP = npcClass.CastAni.onDestory;
                npcDelegate      -= npcmove.delegateUpdate;
                npcDelegate      -= playermove.delegateUpdate;

                GetComponentInChildren <attackSystem>().enabled = false;

                npcclass.movementStateP = npcClass.movementState.jumpingBothCanMove; //強制鎖定為跳躍  處理死亡時往後擊飛
                inDeadHitFly            = true;
                if (transform.localScale.x > 0f)                                     //大過0面向左邊,反則右邊
                {
                    rigidbody2d.velocity = new Vector2(2.5f, 10);
                }
                else
                {
                    rigidbody2d.velocity = new Vector2(-2.5f, 10);
                }
            }
            else                                                                              //當死亡時就一直做
            {
                if (npcclass.movementStateP == npcClass.movementState.landed && inDeadHitFly) //landed時就毀掉自己
                {
                    Destroy(gameObject);

                    Instantiate(SoulsParticlePrefab, transform.position, Quaternion.identity);
                    //playerData.playerSouls += npcclass.souls; //玩家靈魂增加
                }
            }
        }
        #endregion
    }
    // Update is called once per frame
    void Update()
    {
        if (npcDelegate != null)
        {
            if (gameStateDataClass.staticGameStateDataClass != null)
            {
                if (gameStateDataClass.staticGameStateDataClass.gamestate == gameStateDataClass.gameState.gameover && !stopMoveOnce)
                {
                    stopMoveOnce = true;
                    if (npcclass.Species != npcClass.SpeciesType.robot)
                    {
                        npcDelegate -= npcmove.delegateUpdate;
                        npcDelegate -= playermove.delegateUpdate;
                    }
                    rigidbody2d.velocity = Vector3.zero;
                }
            }

            npcDelegate.Invoke();
        }
    }
    void NpcDead()   //do once
    {
        #region npc死亡時做的程式
        if (npcclass.liveStateP == npcClass.liveState.dead && npcclass.TypeP != npcClass.Type.contorl) //當死亡時
        {
            if (!IsAlreadyStartDeadFunction)                                                           //當死亡時只做一次
            {
                IsAlreadyStartDeadFunction = true;

                if (npcclass.Species != npcClass.SpeciesType.robot)
                {
                    switch (npcclass.TypeP)
                    {
                    case npcClass.Type.normal:
                        if (whoKillThis != "void")
                        {
                            spawnHPParticle(10);
                        }
                        break;

                    case npcClass.Type.spyder:
                        if (whoKillThis != "void")
                        {
                            spawnHPParticle(1);
                        }

                        break;
                    }
                }


                GetComponent <Rigidbody2D>().gravityScale = 1.0f;

                //GetComponent<npcMove>().enabled = false;
                npcclass.CastAniP = npcClass.CastAni.onDestory;

                if (npcmove != null)
                {
                    npcDelegate -= npcmove.delegateUpdate;
                }
                if (playermove != null)
                {
                    npcDelegate -= playermove.delegateUpdate;
                }

                if (npcclass.TypeP == npcClass.Type.normal && GetComponentInChildren <attackSystem>())
                {
                    GetComponentInChildren <attackSystem>().enabled = false;
                }

                //npcclass.movementStateP = npcClass.movementState.jumpingBothCanMove;//強制鎖定為跳躍  處理死亡時往後擊飛
                npcclass.CastAniP = npcClass.CastAni.onDestory;
                if (thisAnimation != null)
                {
                    thisAnimation.state.SetAnimation(0, "hit_sword", false);
                    thisAnimation.loop = false;
                }
                if (TestAnimator != null && npcclass.Species == npcClass.SpeciesType.alien)
                {
                    TestAnimator.SetTrigger("ondead");
                }
                inDeadHitFly = true;
                npcDelegate += spyDerSpecDeadAni;
                //rigidbody2d.velocity = new Vector2(5f * (Function.RandomNumber(10) / 10) * transform.localScale.x, 20 * (Function.RandomNumber(10) / 10)); //大過0面向左邊,反則右邊
                if (transform.localScale.x > 0f)   //大過0面向左邊,反則右邊
                //rigidbody2d.velocity = new Vector2(2.5f, 10);

                {
                    rigidbody2d.velocity = new Vector2(Function.RandomNumber(10) + 5, Function.RandomNumber(15) + 10);    //大過0面向左邊,反則右邊
                }
                else
                {
                    //rigidbody2d.velocity = new Vector2(-2.5f, 10);
                    rigidbody2d.velocity = new Vector2(-Function.RandomNumber(10) + 5, Function.RandomNumber(15) + 10);  //大過0面向左邊,反則右邊
                }
            }
            else                                                                                                                        //當死亡時就一直做
            {
                if (npcclass.movementStateP == npcClass.movementState.landed && inDeadHitFly && npcclass.TypeP != npcClass.Type.spyder) //landed時就毀掉自己
                {
                    DeadFadeOut();
                    //playerData.playerSouls += npcclass.souls; //玩家靈魂增加
                }
                if (npcclass.liveStateP == npcClass.liveState.dead && npcclass.TypeP == npcClass.Type.spyder)
                {
                    DeadFadeOut();
                }
            }
        }
        #endregion
    }