Beispiel #1
0
        public void TakeDamage(Damager damager, bool ignoreInvincible = false)
        {
            if ((m_Invulnerable && !ignoreInvincible) || m_CurrentHealth <= 0)
            {
                return;
            }

            //we can reach that point if the damager was one that was ignoring invincible state.
            //We still want the callback that we were hit, but not the damage to be removed from health.
            if (!m_Invulnerable)
            {
                m_CurrentHealth -= damager.damage;
                OnHealthSet.Invoke(this);
            }

            m_DamageDirection = transform.position + (Vector3)centreOffset - damager.transform.position;

            OnTakeDamage.Invoke(damager, this);

            if (m_CurrentHealth <= 0)
            {
                OnDie.Invoke(damager, this);
                m_ResetHealthOnSceneReload = true;
                EnableInvulnerability();
                if (disableOnDeath)
                {
                    gameObject.SetActive(false);
                }
            }
        }
Beispiel #2
0
        public void OnHurt(Damager damager, Damageable damageable)
        {
            //if the player don't have control, we shouldn't be able to be hurt as this wouldn't be fair
            if (!PlayerInput.Instance.HaveControl)
            {
                return;
            }

            UpdateFacing(damageable.GetDamageDirection().x > 0f);
            damageable.EnableInvulnerability();

            m_Animator.SetTrigger(m_HashHurtPara);

            //we only force respawn if helath > 0, otherwise both forceRespawn & Death trigger are set in the animator, messing with each other.
            if (damageable.CurrentHealth > 0 && damager.forceRespawn)
            {
                m_Animator.SetTrigger(m_HashForcedRespawnPara);
            }

            m_Animator.SetBool(m_HashGroundedPara, false);
            hurtAudioPlayer.PlayRandomSound();

            //if the health is < 0, mean die callback will take care of respawn
            if (damager.forceRespawn && damageable.CurrentHealth > 0)
            {
                StartCoroutine(DieRespawnCoroutine(false, true));
            }
        }
        public void ShieldHit(Damager damager, Damageable damageable)
        {
            Vector3 localPosition = transform.InverseTransformPoint(damager.transform.position);

            m_Material.SetVector("_HitPosition", localPosition);
            m_Intensity = 1.0f;
        }
Beispiel #4
0
        //En la escena
        void OnSceneGUI()
        {
            Damager damager = (Damager)target;

            //si Damager no esta activo retorne y apague el cuadrito verde que se dibuja en la escena
            if (!damager.enabled)
            {
                return;
            }
            //en una matrix asigne la posicion local del transform del damager
            Matrix4x4 handleMatrix = damager.transform.localToWorldMatrix;

            handleMatrix.SetRow(0, Vector4.Scale(handleMatrix.GetRow(0), new Vector4(1f, 1f, 0f, 1f)));
            handleMatrix.SetRow(1, Vector4.Scale(handleMatrix.GetRow(1), new Vector4(1f, 1f, 0f, 1f)));
            handleMatrix.SetRow(2, new Vector4(0f, 0f, 1f, damager.transform.position.z));
            using (new Handles.DrawingScope(handleMatrix))
            {   //asigno a la variable s_Box.. declarada arriba las opciones dadas en el inspector
                s_BoxBoundsHandle.center = damager.offset;
                s_BoxBoundsHandle.size   = damager.size;

                s_BoxBoundsHandle.SetColor(s_EnabledColor); //Asigno el color dado arriba
                EditorGUI.BeginChangeCheck();               //Comprueba si algo a cambiado en el bloque de codigo
                s_BoxBoundsHandle.DrawHandle();
                if (EditorGUI.EndChangeCheck())             //finaliza los cambios echos en beginchangeCheck
                {
                    Undo.RecordObject(damager, "Modify Damager");

                    damager.size   = s_BoxBoundsHandle.size;
                    damager.offset = s_BoxBoundsHandle.center;
                }
            }
        }
Beispiel #5
0
        void OnSceneGUI()
        {
            Damager damager = (Damager)target;

            if (!damager.enabled)
            {
                return;
            }

            Matrix4x4 handleMatrix = damager.transform.localToWorldMatrix;

            ////Hotkang 2018.7.24 疑问: 用处何在? 注释掉后暂未发现区别
            ////Debug.Log(handleMatrix);
            handleMatrix.SetRow(0, Vector4.Scale(handleMatrix.GetRow(0), new Vector4(1f, 1f, 0f, 1f)));
            handleMatrix.SetRow(1, Vector4.Scale(handleMatrix.GetRow(1), new Vector4(1f, 1f, 0f, 1f)));
            handleMatrix.SetRow(2, new Vector4(0f, 0f, 1f, damager.transform.position.z));
            ////Debug.Log(handleMatrix);
            using (new Handles.DrawingScope(handleMatrix))
            {
                s_BoxBoundsHandle.center = damager.offset;
                s_BoxBoundsHandle.size   = damager.size;

                s_BoxBoundsHandle.SetColor(s_EnabledColor);
                EditorGUI.BeginChangeCheck();
                s_BoxBoundsHandle.DrawHandle();
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(damager, "Modify Damager");

                    damager.size   = s_BoxBoundsHandle.size;
                    damager.offset = s_BoxBoundsHandle.center;
                }
            }
        }
Beispiel #6
0
        //Si es herido
        public void OnHurt(Damager damager, Damageable damageable)
        {
            //if the player don't have control, we shouldn't be able to be hurt as this wouldn't be fair
            if (!PlayerInput.Instance.HaveControl)
            {
                return;
            }
            //Actualice la cara segun la direccion del daño obtenido
            UpdateFacing(damageable.GetDamageDirection().x > 0f); //si es mayor a cero lanzo el ataque hacia la derecha y me impacto en la izquerda
            damageable.EnableInvulnerability();                   //activa invulnerabilidad
            //Trigger de daño recibido al animador
            m_Animator.SetTrigger(m_HashHurtPara);                //Llama a HurtSMB que activa el flickering

            //solo forzamos la reaparición si helath > 0, de lo contrario, los activadores forceRespawn y Death se establecen en el animador, jugando entre sí.
            //we only force respawn if helath > 0, otherwise both forceRespawn & Death trigger are set in the animator, messing with each other.
            if (damageable.CurrentHealth > 0 && damager.forceRespawn)
            {
                m_Animator.SetTrigger(m_HashForcedRespawnPara);
            }
            //piso falso
            m_Animator.SetBool(m_HashGroundedPara, false);
            hurtAudioPlayer.PlayRandomSound();
            // si la salud es < 0, significa muerte la devolución de llamada tomara cuidado de reaparecer
            //if the health is < 0, mean die callback will take care of respawn
            if (damager.forceRespawn && damageable.CurrentHealth > 0)
            {
                StartCoroutine(DieRespawnCoroutine(false, true));
            }
        }
Beispiel #7
0
        //Tomar dañollamado desde el script Damager
        public void TakeDamage(Damager damager, bool ignoreInvincible = false)
        {   //si es invulnerable y no esta en ignorar invencible o  la sangre es menor a cero retorne el codigo
            if ((m_Invulnerable && !ignoreInvincible) || m_CurrentHealth <= 0)
            {
                return;
            }
            //podemos encontrar ese punto si el damager fue uno que estaba ignorando el estado invencible
            //we can reach that point if the damager was one that was ignoring invincible state.
            //Todavía queremos la devolución de llamada que golpeo, pero no el daño que se eliminará de la salud.
            //We still want the callback that we were hit, but not the damage to be removed from health.

            if (!m_Invulnerable)
            {
                m_CurrentHealth -= damager.damage; //resta el daño
                OnHealthSet.Invoke(this);          //configura dos metodos en el canvas
            }
            //Direccion Daño= la posicion actual + vector 3 * centreOffset: 0 , 1 lo que hace que se posicione mas al centro - la posicion del dañador
            m_DamageDirection = transform.position + (Vector3)centreOffset - damager.transform.position;

            OnTakeDamage.Invoke(damager, this);//Este evento llama al script y metodo deseado en el inspector para el jugador llama OnHurt en el script PlayerCharacter para el enemigo llama EnemyBehaviour.Hit
            //Si muere
            if (m_CurrentHealth <= 0)
            {
                OnDie.Invoke(damager, this);//evento ondie que llama a ondie en PlayerCharacter
                m_ResetHealthOnSceneReload = true;
                EnableInvulnerability();
                if (disableOnDeath)
                {
                    gameObject.SetActive(false);
                }
            }
        }
        public void GetReferences()
        {
            m_Renderer = GetComponent <MeshRenderer>();
            m_Filter   = GetComponent <MeshFilter>();

            m_BoxCollider = GetComponent <BoxCollider2D>();

            m_Damager          = GetComponent <Damager>();
            m_Bubbles          = transform.Find("Bubbles").GetComponent <ParticleSystem>();
            m_Steam            = transform.Find("Steam").GetComponent <ParticleSystem>();
            m_BuoyancyEffector = GetComponent <BuoyancyEffector2D>();
        }
        public void TakeDamage(Damager damager, bool canDamageInvincibility = false)
        {
            if (m_Invulnerable && !canDamageInvincibility)
            {
                return;
            }

            m_IsAlive = false;
            OnDie.Invoke(damager, this);
            if (disableOnDeath)
            {
                gameObject.SetActive(false);
            }
        }
Beispiel #10
0
        public void OnHurt(Damager damager, Damageable damageable)
        {
            //if the player don't have control, we shouldn't be able to be hurt as this wouldn't be fair
            if (!PlayerInput.Instance.HaveControl)
            {
                return;
            }

            damageable.EnableInvulnerability();

            //if the health is < 0, mean die callback will take care of respawn
            if (damager.forceRespawn && damageable.CurrentHealth > 0)
            {
                GameController.isGameOver = true;
            }
        }
        public void Die(Damager damager, Damageable damageable)
        {
            Vector2 throwVector   = new Vector2(0, 2.0f);
            Vector2 damagerToThis = damager.transform.position - transform.position;

            throwVector.x = Mathf.Sign(damagerToThis.x) * -4.0f;
            SetMoveVector(throwVector);

            m_Animator.SetTrigger(m_HashDeathPara);

            dieAudio.PlayRandomSound();

            m_Dead             = true;
            m_Collider.enabled = false;

            CameraShaker.Shake(0.15f, 0.3f);
        }
        void OnSceneGUI()
        {
            Damager damager = (Damager)target;

            if (!damager.enabled || m_UseTriggerColliderProp.boolValue)
            {
                return;
            }

            Matrix4x4 handleMatrix = damager.transform.localToWorldMatrix;

            handleMatrix.SetRow(0, Vector4.Scale(handleMatrix.GetRow(0), new Vector4(1f, 1f, 0f, 1f)));
            handleMatrix.SetRow(1, Vector4.Scale(handleMatrix.GetRow(1), new Vector4(1f, 1f, 0f, 1f)));
            handleMatrix.SetRow(2, new Vector4(0f, 0f, 1f, damager.transform.position.z));
            using (new Handles.DrawingScope(handleMatrix))
            {
                s_BoxBoundsHandle.center = damager.offset;
                s_BoxBoundsHandle.size   = damager.size;

                s_BoxBoundsHandle.SetColor(s_EnabledColor);

                //Check if any control was changed inside a block of code.
                EditorGUI.BeginChangeCheck();

                // Block of code with controls
                // this may set GUI.changed to true.
                s_BoxBoundsHandle.DrawHandle();

                //if true, GUI.changed was set to true
                if (EditorGUI.EndChangeCheck())
                {
                    // Code to execute if GUI.changed
                    // was set to true inside the block of code above.

                    //Records any changes done on the object after the RecordObject function
                    //name: The title of the action to appear in the undo history (i.e. visible in the undo menu).
                    Undo.RecordObject(damager, "Modify Damager");

                    damager.size   = s_BoxBoundsHandle.size;
                    damager.offset = s_BoxBoundsHandle.center;
                }
            }
        }
        public void Hit(Damager damager, Damageable damageable)
        {
            if (damageable.CurrentHealth <= 0)
            {
                return;
            }

            m_Animator.SetTrigger(m_HashHitPara);

            Vector2 throwVector   = new Vector2(0, 3.0f);
            Vector2 damagerToThis = damager.transform.position - transform.position;

            throwVector.x = Mathf.Sign(damagerToThis.x) * -2.0f;
            m_MoveVector  = throwVector;

            if (m_FlickeringCoroutine != null)
            {
                StopCoroutine(m_FlickeringCoroutine);
                m_SpriteRenderer.color = m_OriginalColor;
            }

            m_FlickeringCoroutine = StartCoroutine(Flicker(damageable));
            CameraShaker.Shake(0.15f, 0.3f);
        }
 public void OnHitNonDamageable(Damager origin)
 {
     FindSurface(origin.LastHit);
 }
 public void OnHitDamageable(Damager origin, Damageable damageable)
 {
     FindSurface(origin.LastHit);
 }