Beispiel #1
0
    IEnumerator Beam()
    {
        int numLoops = 0;

        if (ship != null)
        {
            closestGameObject = StaticMethods.ClosestTargetToShipWithinRange(enemyList, transform.position, transform.position, shootRangeFromThisWeapon);
            enemyList.Remove(closestGameObject);
        }

        while (numLoops < durationOfBeam)
        {
            if (muzzle != null && closestGameObject != null)
            {
                laserBeam.Trigger(muzzle.transform.position, closestGameObject.transform.position);
            }

            yield return(new WaitForSeconds(timeBetweenBeams));

            numLoops++;
        }
        if (closestGameObject != null)
        {
            OnLaserObject(closestGameObject.GetComponent <Collider>(), closestGameObject.transform.position);
        }
        yield return(null);
    }
Beispiel #2
0
    IEnumerator Shock5()
    {
        int numLoops = 0;

        if (closestGameObject4 != null)
        {
            closestGameObject5 = StaticMethods.ClosestTargetToShipWithinRange(enemyList, closestGameObject4.transform.position, closestGameObject4.transform.position, shootRangeFromPlayer);
            enemyList.Remove(closestGameObject5);
        }

        yield return(new WaitForSeconds(4 * timeBetweenJumps));

        while (numLoops < durationOfLightning)
        {
            if (closestGameObject4 != null && closestGameObject5 != null)
            {
                lightningBolt.Trigger(closestGameObject4.transform.position, closestGameObject5.transform.position);
            }

            yield return(new WaitForSeconds(timeBetweenBolts));

            numLoops++;
        }
        if (closestGameObject5 != null)
        {
            OnShockObject(closestGameObject5.GetComponent <Collider>(), closestGameObject5.transform.position, 0.4f);
        }
        yield return(null);
    }
Beispiel #3
0
    protected override void Start()
    {
        base.Start();
        secondaryWeapon = GameObject.FindGameObjectWithTag("Secondary Weapon");
        shootRange      = secondaryWeapon.gameObject.GetComponent <ShootAttack>().shootRange;

        if (ship != null)
        {
            Enemies.AddRange(GameObject.FindGameObjectsWithTag("Enemy"));
            closestGameObject = StaticMethods.ClosestTargetToShipWithinRange(Enemies, transform.position, ship.transform.position, shootRange);
        }
    }
Beispiel #4
0
    protected virtual void Update()
    {
        currentPosition = GetComponent <Transform>().position;
        Enemies.Clear();         // To stop null pointer exception when an enemy dies. Expensive???

        if (target == Target.enemyClosestToPlayer)
        {
            Enemies.AddRange(GameObject.FindGameObjectsWithTag("Enemy"));
            closestGameObject = StaticMethods.ClosestTargetToPlayerWithinRange(Enemies, player.transform.position);
        }

        if (target == Target.enemyClosestToShip && ship != null)
        {
            Enemies.AddRange(GameObject.FindGameObjectsWithTag("Enemy"));
            closestGameObject = StaticMethods.ClosestTargetToShipWithinRange(Enemies, transform.position, ship.transform.position, shootRange);
        }

        if (target == Target.shipsTarget && ship != null)
        {
            Enemies.AddRange(GameObject.FindGameObjectsWithTag("Enemy"));
            closestGameObject = StaticMethods.ClosestTargetToShipWithinRange(Enemies, transform.position, transform.position, shootRange);
        }

        if (closestGameObject != null)
        {
            float dist = Vector3.Distance(closestGameObject.transform.position, transform.position);
            if (dist <= shootRange && !weaponDisabled)
            {
                Vector3    relativePos = closestGameObject.transform.position - transform.position;
                Quaternion rotation    = Quaternion.LookRotation(relativePos);
                transform.rotation = Quaternion.Lerp(transform.rotation, rotation, Time.deltaTime * turnSpeed);
                weaponController.Shoot();
            }
            else
            {
                Vector3    relativePos = closestGameObject.transform.position - transform.position;
                Quaternion rotation    = Quaternion.LookRotation(relativePos);
                transform.rotation = Quaternion.Lerp(transform.rotation, rotation, Time.deltaTime * turnSpeed);
            }
        }
        else
        {
            if (currentPosition == lastPosition)              // if the object that this is on is not moving
            {
                if (target == Target.enemyClosestToShip)
                {
                    transform.rotation = GameObject.FindGameObjectWithTag("Player Rotation").GetComponent <Transform>().rotation;
                }
                else
                {
                    if (ship != null && target != Target.shipsTarget)
                    {
                        transform.rotation = GameObject.FindGameObjectWithTag("Player Rotation").GetComponent <Transform>().rotation;
                    }
                    else
                    {
                        Vector3    relativePos = new Vector3(Camera.main.transform.position.x, 0f, Camera.main.transform.position.z) - transform.position;
                        Quaternion rotation    = Quaternion.LookRotation(relativePos);
                        transform.rotation = Quaternion.Lerp(transform.rotation, rotation, Time.deltaTime * turnSpeed);
                    }
                }
            }
            else
            {
                if (target != Target.shipsTarget)
                {
                    transform.rotation = GameObject.FindGameObjectWithTag("Player Rotation").GetComponent <Transform>().rotation;
                }
                else
                {
                    Vector3    relativePos = new Vector3(Camera.main.transform.position.x, 0f, Camera.main.transform.position.z) - transform.position;
                    Quaternion rotation    = Quaternion.LookRotation(relativePos);
                    transform.rotation = Quaternion.Lerp(transform.rotation, rotation, Time.deltaTime * turnSpeed);
                }
            }
            lastPosition = currentPosition;
        }
    }