Ejemplo n.º 1
0
        // Called by OnReceiveMessage.
        void Damaged(Damageable.DamageMessage damageMessage)
        {
            // Set the Hurt parameter of the animator.
            m_Animator.SetTrigger(m_HashHurt);

            // Find the direction of the damage.
            Vector3 forward = damageMessage.damageSource - transform.position;

            forward.y = 0f;

            Vector3 localHurt = transform.InverseTransformDirection(forward);

            // Set the HurtFromX and HurtFromY parameters of the animator based on the direction of the damage.
            m_Animator.SetFloat(m_HashHurtFromX, localHurt.x);
            m_Animator.SetFloat(m_HashHurtFromY, localHurt.z);

            // Shake the camera.
            CameraShake.Shake(CameraShake.k_PlayerHitShakeAmount, CameraShake.k_PlayerHitShakeTime);

            // Play an audio clip of being hurt.
            if (hurtAudioPlayer != null)
            {
                hurtAudioPlayer.PlayRandomClip();
            }

            if (damageMessage.effect != null)
            {
                switch (damageMessage.effect)
                {
                case Magic.MagicEffect.Burn:
                {
                    StartCoroutine(OnBurn(damageMessage.magicEffectLasting, 1, damageMessage.amount));
                    break;
                }

                case Magic.MagicEffect.Slow:
                {
                    StartCoroutine(OnSlow(damageMessage.magicEffectLasting, 0.50f));
                    break;
                }

                case Magic.MagicEffect.Paralyze:
                {
                    StartCoroutine(OnParalyze(damageMessage.magicEffectLasting));
                    break;
                }
                }
            }
        }
        // Called by OnReceiveMessage.
        void Damaged(Damageable.DamageMessage damageMessage)
        {
            // Set the Hurt parameter of the animator.
            m_Animator.SetTrigger(m_HashHurt);

            // Find the direction of the damage.
            Vector3 forward = damageMessage.damageSource - transform.position;

            forward.y = 0f;

            Vector3 localHurt = transform.InverseTransformDirection(forward);

            // Set the HurtFromX and HurtFromY parameters of the animator based on the direction of the damage.
            m_Animator.SetFloat(m_HashHurtFromX, localHurt.x);
            m_Animator.SetFloat(m_HashHurtFromY, localHurt.z);

            // Shake the camera.
            CameraShake.Shake(CameraShake.k_PlayerHitShakeAmount, CameraShake.k_PlayerHitShakeTime);

            // Play an audio clip of being hurt.
            if (hurtAudioPlayer != null)
            {
                hurtAudioPlayer.PlayRandomClip();
            }

            //=========================================================================================
            Dictionary <string, object> myDic = new Dictionary <string, object>();

            //Type
            myDic.Add("Type", "Damaged");

            //TimeStamp
            myDic.Add("TimeStamp", Time.time);

            //Transform
            myDic.Add("PositionX", transform.position.x);
            myDic.Add("PositionY", transform.position.y);
            myDic.Add("PositionZ", transform.position.z);

            //PlayerID
            myDic.Add("PlayerID", /*PlayerData.player_id*/ 0);

            PlayerEventTrack.EventList.Add(myDic);
            Debug.Log("Player Damaged");
            //=========================================================================================
        }
Ejemplo n.º 3
0
        public void BeHit(int decHP, ICreatureBehavior source)
        {
            m_Animator.SetTrigger(m_HashHurt);

            // Find the direction of the damage.
            Vector3 forward = source.GetTransform().position - transform.position;

            forward.y = 0f;

            Vector3 localHurt = transform.InverseTransformDirection(forward);

            // Set the HurtFromX and HurtFromY parameters of the animator based on the direction of the damage.
            m_Animator.SetFloat(m_HashHurtFromX, localHurt.x);
            m_Animator.SetFloat(m_HashHurtFromY, localHurt.z);

            var msg = new Damageable.DamageMessage()
            {
                amount     = decHP,
                damager    = this,
                direction  = Vector3.up,
                stopCamera = false
            };

            m_Damageable.ApplyDamage(msg);

            if (IsMine)
            {
                // Shake the camera.
                CameraShake.Shake(CameraShake.k_PlayerHitShakeAmount, CameraShake.k_PlayerHitShakeTime);

                // Play an audio clip of being hurt.
                if (hurtAudioPlayer != null)
                {
                    hurtAudioPlayer.PlayRandomClip();
                }
                if (m_healthUI != null)
                {
                    m_healthUI.ChangeHitPointUI(m_Damageable);
                }
            }
        }
Ejemplo n.º 4
0
        public void ApplyDamage(Damageable.DamageMessage msg)
        {
            if (msg.damager.name == "Staff")
            {
                CameraShake.Shake(0.06f, 0.1f);
            }

            float verticalDot   = Vector3.Dot(Vector3.up, msg.direction);
            float horizontalDot = Vector3.Dot(transform.right, msg.direction);

            Vector3 pushForce = transform.position - msg.damageSource;

            pushForce.y = 0;

            transform.forward = -pushForce.normalized;
            controller.AddForce(pushForce.normalized * 5.5f, false);

            controller.animator.SetFloat(hashVerticalDot, verticalDot);
            controller.animator.SetFloat(hashHorizontalDot, horizontalDot);

            controller.animator.SetTrigger(hashHit);

            hitAudio.PlayRandomClip();
        }