//a method called to apply damage to a target (position)
        private void ApplyDamage(GameObject targetObject, FactionEntity target, Vector3 targetPosition)
        {
            damage.TriggerAttack(target, targetPosition, sourceFactionID, true); //deal damage
            didDamage = true;

            //show damage effect:
            gameMgr.EffectPool.SpawnEffectObj(hitEffect, transform.position, Quaternion.identity, targetObject.transform); //Get the spawn effect obj
            AudioManager.Play(target ? target.AudioSourceComp : targetObject.GetComponent <AudioSource>(), hitAudio, false);

            if (target && childOnDamage == true) //if the attack object is supposed to become a child object of its target on damage:
            {
                transform.SetParent(target.transform, true);
            }

            if (destroyOnDamage == true) //if this object gets hidden on damage
            {
                effectObjComp.Disable(); //disable from the effect object component
                isActive = false;        //set as inactive
            }
        }
Example #2
0
        protected void ToggleSourceTargetEffect(bool enable)
        {
            if (enable)
            {
                if (sourceEffect != null)
                {
                    currSourceEffect = gameMgr.EffectPool.SpawnEffectObj(
                        sourceEffect,
                        transform.position,
                        sourceEffect.transform.rotation,
                        transform,
                        false); //spawn the source effect on the source unit and don't enable the life timer
                }
                if (targetEffect != null)
                {
                    currTargetEffect = gameMgr.EffectPool.SpawnEffectObj(
                        targetEffect,
                        target.transform.position,
                        targetEffect.transform.rotation,
                        target.transform,
                        false); //spawn the target effect on the target and don't enable the life timer
                }
            }
            else
            {
                if (currSourceEffect != null)   //if the source unit effect was assigned and it's still valid
                {
                    currSourceEffect.Disable(); //stop it
                    currSourceEffect = null;
                }

                if (currTargetEffect != null)   //if a target effect was assigned and it's still valid
                {
                    currTargetEffect.Disable(); //stop it
                    currTargetEffect = null;
                }
            }
        }