void Update()
        {
            if (target)
            {
                Quaternion targetlook = Quaternion.LookRotation(target.transform.position - this.transform.position);
                this.transform.rotation = Quaternion.Lerp(this.transform.rotation, targetlook, Time.deltaTime * 3);

                Vector3 dir       = (target.transform.position - transform.position).normalized;
                float   direction = Vector3.Dot(dir, transform.forward);

                if (direction > 0.9f)
                {
                    if (weapon)
                    {
                        weapon.LaunchWeapon(indexWeapon);
                    }
                }
                // AI attack the target for a while (3 sec)
                if (Time.time > timeAIattack + 3)
                {
                    target = null;
                    // AI forget this target and try to looking new target
                }
            }
            else
            {
                for (int t = 0; t < TargetTag.Length; t++)
                {
                    // AI find target only in TargetTag list
                    TargetCollector collector = WeaponSystem.Finder.FindTargetTag(TargetTag [t]);
                    if (collector != null)
                    {
                        GameObject[] objs     = collector.Targets;
                        float        distance = Distance;
                        for (int i = 0; i < objs.Length; i++)
                        {
                            if (objs [i] != null)
                            {
                                float dis = Vector3.Distance(objs [i].transform.position, transform.position);

                                if (distance > dis)
                                {
                                    // Select closer target
                                    distance = dis;
                                    target   = objs [i];
                                    if (weapon)
                                    {
                                        indexWeapon = Random.Range(0, weapon.WeaponLists.Length);
                                    }
                                    timeAIattack = Time.time;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        void chainDamage()
        {
            int count = 0;

            for (int t = 0; t < TargetTag.Length; t++)
            {
                TargetCollector collector = WeaponSystem.Finder.FindTargetTag(TargetTag [t]);
                if (collector != null)
                {
                    GameObject[] objs     = collector.Targets;
                    float        distance = Distance;


                    for (int i = 0; i < objs.Length; i++)
                    {
                        if (objs [i] != null)
                        {
                            Vector3 dir       = (objs [i].transform.position - this.transform.position).normalized;
                            float   direction = Vector3.Dot(dir, this.transform.forward);
                            float   dis       = Vector3.Distance(objs [i].transform.position, this.transform.position);
                            if (dis < distance)
                            {
                                if (direction >= Direction)
                                {
                                    if (ChainObject)
                                    {
                                        if (count <= NumberChain)
                                        {
                                            GameObject chain;
                                            Quaternion targetlook = Quaternion.LookRotation(objs [i].transform.position - this.transform.position);
                                            if (WeaponSystem.Pool != null)
                                            {
                                                chain = WeaponSystem.Pool.Instantiate(ChainObject, this.transform.position, targetlook);
                                            }
                                            else
                                            {
                                                chain = (GameObject)GameObject.Instantiate(ChainObject, this.transform.position, targetlook);
                                            }

                                            DamageBase dmg = chain.GetComponent <DamageBase> ();
                                            if (dmg)
                                            {
                                                dmg.TargetTag = TargetTag;
                                            }
                                            count += 1;
                                        }
                                    }
                                }
                                distance = dis;
                            }
                        }
                    }
                }
            }
        }
Пример #3
0
        private void OnGUI()
        {
            if (OnActive)
            {
                if (Seeker)
                {
                    if (target)
                    {
                        DrawTargetLockon(target.transform, true);
                    }

                    for (int t = 0; t < TargetTag.Length; t++)
                    {
                        TargetCollector collector = WeaponSystem.Finder.FindTargetTag(TargetTag [t]);
                        if (collector != null)
                        {
                            GameObject[] objs = collector.Targets;
                            for (int i = 0; i < objs.Length; i++)
                            {
                                if (objs [i])
                                {
                                    Vector3 dir       = (objs [i].transform.position - transform.position).normalized;
                                    float   direction = Vector3.Dot(dir, transform.forward);
                                    if (direction >= AimDirection)
                                    {
                                        float dis = Vector3.Distance(objs [i].transform.position, transform.position);
                                        if (DistanceLock > dis)
                                        {
                                            DrawTargetLockon(objs [i].transform, false);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                DrawCrosshair();
            }
        }
Пример #4
0
        private void Update()
        {
            if (CurrentCamera == null)
            {
                CurrentCamera = Camera.main;

                if (CurrentCamera == null)
                {
                    CurrentCamera = Camera.current;
                }
            }
            if (OnActive)
            {
                if (TorqueObject)
                {
                    TorqueObject.transform.Rotate(torqueTemp * Time.deltaTime);
                    torqueTemp = Vector3.Lerp(torqueTemp, Vector3.zero, Time.deltaTime);
                }
                if (Seeker)
                {
                    for (int t = 0; t < TargetTag.Length; t++)
                    {
                        TargetCollector collector = WeaponSystem.Finder.FindTargetTag(TargetTag [t]);

                        if (collector != null)
                        {
                            GameObject[] objs     = collector.Targets;
                            float        distance = int.MaxValue;

                            if (AimObject != null && AimObject.tag == TargetTag [t])
                            {
                                float dis = Vector3.Distance(AimObject.transform.position, transform.position);
                                if (DistanceLock > dis)
                                {
                                    if (distance > dis)
                                    {
                                        if (timetolockcount + TimeToLock < Time.time)
                                        {
                                            distance = dis;
                                            target   = AimObject;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                for (int i = 0; i < objs.Length; i++)
                                {
                                    if (objs [i])
                                    {
                                        Vector3 dir       = (objs [i].transform.position - transform.position).normalized;
                                        float   direction = Vector3.Dot(dir, transform.forward);
                                        float   dis       = Vector3.Distance(objs [i].transform.position, transform.position);
                                        if (direction >= AimDirection)
                                        {
                                            if (DistanceLock > dis)
                                            {
                                                if (distance > dis)
                                                {
                                                    if (timetolockcount + TimeToLock < Time.time)
                                                    {
                                                        distance = dis;
                                                        target   = objs [i];
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (target)
                {
                    float   targetdistance = Vector3.Distance(transform.position, target.transform.position);
                    Vector3 dir            = (target.transform.position - transform.position).normalized;
                    float   direction      = Vector3.Dot(dir, transform.forward);

                    if (targetdistance > DistanceLock || direction <= AimDirection)
                    {
                        Unlock();
                    }
                }

                if (Reloading)
                {
                    ReloadingProcess = ((1 / ReloadTime) * (reloadTimeTemp + ReloadTime - Time.time));
                    if (Time.time >= reloadTimeTemp + ReloadTime)
                    {
                        Reloading = false;
                        if (SoundReloaded)
                        {
                            if (audioSource)
                            {
                                audioSource.PlayOneShot(SoundReloaded);
                            }
                        }
                        Ammo = AmmoMax;
                    }
                }
                else
                {
                    if (Ammo <= 0)
                    {
                        Unlock();
                        Reloading      = true;
                        reloadTimeTemp = Time.time;

                        if (SoundReloading)
                        {
                            if (audioSource)
                            {
                                audioSource.PlayOneShot(SoundReloading);
                            }
                        }
                    }
                }
            }
        }
Пример #5
0
        private void Update()
        {
            if (WeaponSystem.Pool != null && objectPool != null && !objectPool.Active)
            {
                return;
            }

            if (Time.time >= (timeCount + LifeTime) - 0.5f)
            {
                if (GetComponent <Damage> ())
                {
                    GetComponent <Damage> ().Active();
                    timeCount = Time.time;
                }
            }

            if (Target)
            {
                Quaternion rotation = Quaternion.LookRotation(Target.transform.position - transform.transform.position);
                transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Damping);
                Vector3 dir       = (Target.transform.position - transform.position).normalized;
                float   direction = Vector3.Dot(dir, transform.forward);
                if (direction < TargetLockDirection)
                {
                    Target = null;
                }
            }

            if (Seeker)
            {
                if (timetorock > DurationLock)
                {
                    if (!locked && !Target)
                    {
                        float distance = int.MaxValue;
                        for (int t = 0; t < TargetTag.Length; t++)
                        {
                            TargetCollector collector = WeaponSystem.Finder.FindTargetTag(TargetTag [t]);
                            if (collector != null)
                            {
                                GameObject[] objs = collector.Targets;

                                for (int i = 0; i < objs.Length; i++)
                                {
                                    if (objs [i])
                                    {
                                        Vector3 dir       = (objs [i].transform.position - transform.position).normalized;
                                        float   direction = Vector3.Dot(dir, transform.forward);
                                        float   dis       = Vector3.Distance(objs [i].transform.position, transform.position);
                                        if (direction >= TargetLockDirection)
                                        {
                                            if (DistanceLock > dis)
                                            {
                                                if (distance > dis)
                                                {
                                                    distance = dis;
                                                    Target   = objs [i];
                                                }
                                                locked = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    timetorock = 0;
                }
                else
                {
                    timetorock += 1;
                }

                if (Target)
                {
                }
                else
                {
                    locked = false;
                }
            }
        }