Ejemplo n.º 1
0
 void Update()
 {
     Timer += Time.deltaTime;
     if (Timer >= SecondsToDespawn)
     {
         EmeraldAIObjectPool.Despawn(gameObject);
     }
 }
Ejemplo n.º 2
0
        void Update()
        {
            DamageTimer       += Time.deltaTime;
            ActiveLengthTimer += Time.deltaTime;

            if (ActiveLengthTimer >= m_AbilityLength + 0.05f)
            {
                if (m_TargetType == EmeraldAISystem.TargetType.AI)
                {
                    if (m_TargetEmeraldComponent.ActiveEffects.Contains(m_AbilityName))
                    {
                        m_TargetEmeraldComponent.ActiveEffects.Remove(m_AbilityName);
                    }
                }
                else if (m_TargetType == EmeraldAISystem.TargetType.Player)
                {
                    if (m_EmeraldAIPlayerDamage.ActiveEffects.Contains(m_AbilityName))
                    {
                        m_EmeraldAIPlayerDamage.ActiveEffects.Remove(m_AbilityName);
                    }
                }

                if (!m_AudioSource.isPlaying)
                {
                    EmeraldAIObjectPool.Despawn(gameObject);
                }
            }

            if (DamageTimer >= m_DamageIncrement && ActiveLengthTimer <= m_AbilityLength + 0.05f)
            {
                if (m_DamageOverTimeEffect != null)
                {
                    if (m_TargetType == EmeraldAISystem.TargetType.AI)
                    {
                        m_EffectPosition = m_TargetEmeraldComponent.transform.position + new Vector3(0, m_TargetEmeraldComponent.HitPointTransform.localPosition.y, 0);
                    }
                    else
                    {
                        m_EffectPosition = m_TargetTransform.position;
                    }

                    EmeraldAIObjectPool.SpawnEffect(m_DamageOverTimeEffect, m_EffectPosition, Quaternion.identity, m_DamageOverTimeTimeout);
                }

                if (m_DamageOverTimeSound != null)
                {
                    m_AudioSource.PlayOneShot(m_DamageOverTimeSound);
                }

                //Apply damage over time to another AI
                if (m_TargetType == EmeraldAISystem.TargetType.AI)
                {
                    m_TargetEmeraldComponent.Damage(m_DamageAmount);
                    m_AttackerEmeraldComponent.OnDoDamageEvent.Invoke();
                }
                else if (m_TargetType == EmeraldAISystem.TargetType.Player) //Apply damage over time to the player
                {
                    if (m_TargetTransform.GetComponent <EmeraldAIPlayerDamage>() != null)
                    {
                        m_TargetTransform.GetComponent <EmeraldAIPlayerDamage>().SendPlayerDamage(m_DamageAmount, m_AttackerEmeraldComponent.transform, m_AttackerEmeraldComponent);
                        m_AttackerEmeraldComponent.OnDoDamageEvent.Invoke();
                    }
                    else
                    {
                        m_TargetTransform.gameObject.AddComponent <EmeraldAIPlayerDamage>();
                        m_TargetTransform.GetComponent <EmeraldAIPlayerDamage>().SendPlayerDamage(m_DamageAmount, m_AttackerEmeraldComponent.transform, m_AttackerEmeraldComponent);
                        m_AttackerEmeraldComponent.OnDoDamageEvent.Invoke();
                    }
                }
                else if (m_TargetType == EmeraldAISystem.TargetType.NonAITarget) //Apply the damage over time to a non-AI target
                {
                    if (m_TargetTransform.GetComponent <EmeraldAINonAIDamage>() != null)
                    {
                        m_TargetTransform.GetComponent <EmeraldAINonAIDamage>().SendNonAIDamage(m_DamageAmount, m_AttackerEmeraldComponent.transform);
                        m_AttackerEmeraldComponent.OnDoDamageEvent.Invoke();
                    }
                    else
                    {
                        m_TargetTransform.gameObject.AddComponent <EmeraldAINonAIDamage>();
                        m_TargetTransform.GetComponent <EmeraldAINonAIDamage>().SendNonAIDamage(m_DamageAmount, m_AttackerEmeraldComponent.transform);
                        m_AttackerEmeraldComponent.OnDoDamageEvent.Invoke();
                    }
                }

                DamageTimer = 0;
            }

            if (m_TargetType == EmeraldAISystem.TargetType.AI && m_TargetEmeraldComponent.IsDead)
            {
                if (m_TargetEmeraldComponent.ActiveEffects.Contains(m_AbilityName))
                {
                    m_TargetEmeraldComponent.ActiveEffects.Remove(m_AbilityName);
                }
                EmeraldAIObjectPool.Despawn(gameObject);
            }
            else if (m_TargetType == EmeraldAISystem.TargetType.NonAITarget && m_NonAIDamageComponent.Health <= 0)
            {
                if (m_NonAIDamageComponent.ActiveEffects.Contains(m_AbilityName))
                {
                    m_NonAIDamageComponent.ActiveEffects.Remove(m_AbilityName);
                }
                EmeraldAIObjectPool.Despawn(gameObject);
            }
        }
Ejemplo n.º 3
0
        void Update()
        {
            //If the target exceeds the AI's firing angle, fire the projectile towards the last detected destination.
            if (AngleTooBig && !Collided)
            {
                if (TargetTypeRef == TargetType.AI && TargetEmeraldSystem != null && !ProjectileDirectionReceived)
                {
                    AdjustTargetPosition        = TargetEmeraldSystem.HitPointTransform.position - transform.position;
                    ProjectileDirectionReceived = true;
                }
                else if (TargetTypeRef != TargetType.AI && !ProjectileDirectionReceived)
                {
                    AdjustTargetPosition        = EmeraldSystem.m_InitialTargetPosition - new Vector3(EmeraldSystem.transform.position.x, transform.position.y, EmeraldSystem.transform.position.z);
                    ProjectileDirectionReceived = true;
                }

                transform.position = transform.position + AdjustTargetPosition.normalized * Time.deltaTime * ProjectileSpeed;

                if (AdjustTargetPosition != Vector3.zero)
                {
                    transform.rotation = Quaternion.LookRotation(AdjustTargetPosition);
                }
            }

            if (!AngleTooBig)
            {
                //Continue to have our AI projectile follow the direction of its target until it collides with something
                if (!Collided && HeatSeekingRef == HeatSeeking.No && ProjectileDirection != Vector3.zero ||
                    !TargetInView && !Collided && ProjectileDirection != Vector3.zero)
                {
                    DeadTargetDetection();

                    if (TargetTypeRef == TargetType.AI && TargetEmeraldSystem != null && !ProjectileDirectionReceived)
                    {
                        AdjustTargetPosition        = TargetEmeraldSystem.HitPointTransform.position - transform.position;
                        ProjectileDirectionReceived = true;
                    }
                    else if (TargetTypeRef == TargetType.Player && !ProjectileDirectionReceived)
                    {
                        AdjustTargetPosition        = new Vector3(ProjectileDirection.x, ProjectileDirection.y + ProjectileCurrentTarget.localScale.y / 2 + EmeraldSystem.PlayerYOffset, ProjectileDirection.z);
                        ProjectileDirectionReceived = true;
                    }
                    else if (TargetTypeRef == TargetType.NonAITarget && !ProjectileDirectionReceived)
                    {
                        AdjustTargetPosition        = new Vector3(ProjectileDirection.x, ProjectileDirection.y + ProjectileCurrentTarget.localScale.y / 2, ProjectileDirection.z);
                        ProjectileDirectionReceived = true;
                    }

                    transform.position += AdjustTargetPosition.normalized * Time.deltaTime * ProjectileSpeed;
                    transform.rotation  = Quaternion.LookRotation(AdjustTargetPosition);
                }

                if (!Collided && HeatSeekingRef == HeatSeeking.Yes && TargetInView)
                {
                    if (!HeatSeekingFinished)
                    {
                        if (TargetTypeRef == TargetType.AI && TargetEmeraldSystem != null)
                        {
                            AdjustTargetPosition = TargetEmeraldSystem.HitPointTransform.position;
                        }
                        else if (TargetTypeRef == TargetType.Player)
                        {
                            AdjustTargetPosition = new Vector3(ProjectileCurrentTarget.position.x, ProjectileCurrentTarget.position.y + ProjectileCurrentTarget.localScale.y / 2 + EmeraldSystem.PlayerYOffset, ProjectileCurrentTarget.position.z);
                        }
                        else if (TargetTypeRef == TargetType.NonAITarget)
                        {
                            AdjustTargetPosition = new Vector3(ProjectileCurrentTarget.position.x, ProjectileCurrentTarget.position.y + ProjectileCurrentTarget.localScale.y / 2, ProjectileCurrentTarget.position.z);
                        }

                        if (ProjectileCurrentTarget != null)
                        {
                            DeadTargetDetection();

                            transform.position = Vector3.MoveTowards(transform.position, AdjustTargetPosition, Time.deltaTime * ProjectileSpeed);
                            transform.LookAt(AdjustTargetPosition);
                            HeatSeekingTimer += Time.deltaTime;

                            if (HeatSeekingTimer >= HeatSeekingSeconds || TargetEmeraldSystem != null && TargetEmeraldSystem.CurrentHealth <= 0)
                            {
                                LastDirection       = ProjectileCurrentTarget.position - transform.position;
                                HeatSeekingFinished = true;
                            }
                        }
                    }
                    else if (HeatSeekingFinished && LastDirection != Vector3.zero || TargetEmeraldSystem != null && TargetEmeraldSystem.CurrentHealth <= 0)
                    {
                        DeadTargetDetection();

                        if (TargetTypeRef == TargetType.AI && TargetEmeraldSystem != null && !ProjectileDirectionReceived)
                        {
                            AdjustTargetPosition        = TargetEmeraldSystem.HitPointTransform.position - transform.position;
                            ProjectileDirectionReceived = true;
                        }
                        else if (TargetTypeRef != TargetType.AI && !ProjectileDirectionReceived)
                        {
                            AdjustTargetPosition        = new Vector3(LastDirection.x, LastDirection.y, LastDirection.z);
                            ProjectileDirectionReceived = true;
                        }

                        transform.position = transform.position + AdjustTargetPosition.normalized * Time.deltaTime * ProjectileSpeed;

                        if (AdjustTargetPosition != Vector3.zero)
                        {
                            transform.rotation = Quaternion.LookRotation(AdjustTargetPosition);
                        }
                    }
                }
            }

            if (Collided)
            {
                CollisionTimer += Time.deltaTime;
                if (CollisionTimer >= CollisionTime)
                {
                    EmeraldAIObjectPool.Despawn(gameObject);
                }
            }
        }