Exemplo n.º 1
0
 public void Hit(short damage)
 {
     if (hp > 0 && damage > 0)
     {
         if (hp - damage > 0)
         {
             if (!hurtSound.isPlaying)
             {
                 hurtSound.Play();
             }
         }
         else
         {
             if (!dieSound.isPlaying)
             {
                 dieSound.Play();
             }
             skull.Activate();
         }
     }
     hp -= damage;
     if (hp < 0)
     {
         hp = 0;
     }
 }
Exemplo n.º 2
0
    public void Synchronize(bool gameInitializing, byte[] recvData, int beginIndex)
    {
        if (control == null)
        {
            control = GetComponent <Control> ();
        }
        short isCurrAlive = BitConverter.ToInt16(recvData, beginIndex);

        if (isCurrAlive == 1 && (isAlive == 0 || gameInitializing))           // reborn
        {
            control.Reset();
            control.Allow();
            characterController.transform.position = new Vector3(BitConverter.ToSingle(recvData, beginIndex + 10), BitConverter.ToSingle(recvData, beginIndex + 14), BitConverter.ToSingle(recvData, beginIndex + 18));
            characterController.transform.rotation = Quaternion.Euler(0, BitConverter.ToSingle(recvData, beginIndex + 22), 0);
        }
        else if (isCurrAlive == 0 && (isAlive == 1 || gameInitializing))
        {
            control.Disallow();
            characterController.transform.position = new Vector3(0, 20, 55);
            characterController.transform.rotation = Quaternion.Euler(0, 180, 0);
            control.SetDeadCamera();
        }
        if (isCurrAlive == 0 && isAlive == 1 && !gameInitializing)
        {
            characterSound.PlayDieSound();
        }
        else if (isCurrAlive == 1 && (isAlive == 0 || gameInitializing))
        {
            characterSound.PlayRebornSound();
        }
        isAlive = isCurrAlive;
        float prevRebornTimeLeft = rebornTimeLeft;

        rebornTimeLeft = BitConverter.ToSingle(recvData, beginIndex + 2);
        if (prevRebornTimeLeft > 2.3f && rebornTimeLeft <= 2.3f)
        {
            System.GC.Collect();
        }
        short currHp = BitConverter.ToInt16(recvData, beginIndex + 6);

        if (currHp < hp && !gameInitializing)
        {
            characterSound.PlayHurtSound();
            hurt.Activate(0.08f * (hp - currHp));
        }
        hp = currHp;
        if (gameInitializing)
        {
            maxHp = BitConverter.ToInt16(recvData, beginIndex + 8);
            sniper.SetBulletNum(BitConverter.ToInt16(recvData, beginIndex + 26));
            sniper.SetBulletOwn(BitConverter.ToInt16(recvData, beginIndex + 28));
            submachine.SetBulletNum(BitConverter.ToInt16(recvData, beginIndex + 30));
            submachine.SetBulletOwn(BitConverter.ToInt16(recvData, beginIndex + 32));
            medicineNum = BitConverter.ToInt16(recvData, beginIndex + 34);
        }
        upHpLeft = BitConverter.ToInt16(recvData, beginIndex + 36);
        gameBGM.GamePlay(upHpLeft > 0);
    }
Exemplo n.º 3
0
 public void HitCollider(short damage, short criticalDamage, Collider collider)
 {
     if (colliderTable.Contains(collider))
     {
         if (headSet.Contains(collider))
         {
             ((MonsterHP)colliderTable [collider]).Hit(criticalDamage);
             criticalHit.Play();
             criticalHitImage.Activate();
         }
         else
         {
             ((MonsterHP)colliderTable [collider]).Hit(damage);
             hitImage.Activate();
         }
     }
 }