// Update is called once per frame
    void Update()
    {
        if (FindPlayerL)
        {
            Vector3 PlayerPos1;

            PlayerPos1     = FindPlayer().transform.position;
            WhereToFireLC1 = PlayerPos1 - FirePos1.transform.position;
            WhereToFireLC2 = PlayerPos1 - FirePos2.transform.position;
            WhereToFireLC3 = PlayerPos1 - FirePos3.transform.position;
        }

        if (TimerOn)
        {
            time++;
            if (time == reload)
            {
                //Debug.Log ("대포 발사1");
                GameObject enemyBullet1 = ObjectPooling.pool.GetPoolObject_EnemyBullet();
                if (enemyBullet1 == null)
                {
                    return;
                }

                enemyBullet1.transform.position = FirePos1.transform.position;
                enemyBullet1.transform.GetChild(0).GetComponent <TrailRenderer>().Clear();

                enemyBullet1.SetActive(true);
                L1.Play();
                enemyBullet1.GetComponent <Rigidbody> ().velocity = WhereToFireLC1.normalized * bullectLSpeed;
            }
            else if (time == reload * 2)
            {
                GameObject enemyBullet2 = ObjectPooling.pool.GetPoolObject_EnemyBullet();
                if (enemyBullet2 == null)
                {
                    return;
                }

                enemyBullet2.transform.position = FirePos2.transform.position;
                enemyBullet2.transform.GetChild(0).GetComponent <TrailRenderer>().Clear();

                enemyBullet2.SetActive(true);
                L2.Play();
                enemyBullet2.GetComponent <Rigidbody>().velocity = WhereToFireLC2.normalized * bullectLSpeed;
            }
            else if (time == reload * 3)
            {
                GameObject enemyBullet3 = ObjectPooling.pool.GetPoolObject_EnemyBullet();
                if (enemyBullet3 == null)
                {
                    return;
                }

                enemyBullet3.transform.position = FirePos3.transform.position;
                enemyBullet3.transform.GetChild(0).GetComponent <TrailRenderer>().Clear();

                enemyBullet3.SetActive(true);
                L3.Play();
                enemyBullet3.GetComponent <Rigidbody>().velocity = WhereToFireLC3.normalized * bullectLSpeed;


                time    = 0;
                TimerOn = false;
            }
        }
        else
        {
            FindPlayerL = false;
        }
    }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        if (FindEnemyL)
        {
            Vector3 closeEnemyPos1;
            Vector3 closeEnemyPos2;
            Vector3 closeEnemyPos3;
            if (GameObject.FindGameObjectWithTag("EnemyL") != null)
            {
                CloseEn1       = FindClosestEnemyC1();
                CloseEn2       = FindClosestEnemyC2();
                CloseEn3       = FindClosestEnemyC3();
                closeEnemyPos1 = new Vector3(CloseEn1.transform.position.x, CloseEn1.transform.position.y, CloseEn1.transform.position.z);
                closeEnemyPos2 = new Vector3(CloseEn2.transform.position.x, CloseEn2.transform.position.y, CloseEn2.transform.position.z);
                closeEnemyPos3 = new Vector3(CloseEn3.transform.position.x, CloseEn3.transform.position.y, CloseEn3.transform.position.z);

                WhereToFireLC1 = closeEnemyPos1 - Fire_1.position;
                WhereToFireLC2 = closeEnemyPos2 - Fire_2.position;
                WhereToFireLC3 = closeEnemyPos3 - Fire_3.position;
            }
            else
            {
                time = 0;
            }
        }

        if (TimerOn)
        {
            time++;
            if (time == reload)
            {
                //Debug.Log ("대포 발사1");
                Vector3 FirePos_1 = Fire_1.position;

                GameObject Bullet = ObjectPooling.pool.GetPoolObject_Bullet();
                if (Bullet == null)
                {
                    return;
                }

                Bullet.GetComponent <BulletCtrl> ().Enemy = CloseEn1;

                Bullet.transform.position = FirePos_1;


                Bullet.SetActive(true);
                L1.Play();
                Bullet.GetComponent <Rigidbody> ().velocity = WhereToFireLC1.normalized * bullectLSpeed;

                Bullet.GetComponent <TrailRenderer> ().Clear();
            }
            else if (time == reload * 2)
            {
                //Debug.Log ("대포 발사2");
                Vector3 FirePos_2 = Fire_2.position;

                GameObject Bullet = ObjectPooling.pool.GetPoolObject_Bullet();
                if (Bullet == null)
                {
                    return;
                }

                Bullet.GetComponent <BulletCtrl> ().Enemy = CloseEn2;

                Bullet.transform.position = FirePos_2;

                Bullet.SetActive(true);
                L2.Play();
                Bullet.GetComponent <Rigidbody> ().velocity = WhereToFireLC2.normalized * bullectLSpeed;

                Bullet.GetComponent <TrailRenderer> ().Clear();
            }
            else if (time == reload * 3)
            {
                //Debug.Log ("대포 발사3");
                Vector3 FirePos_3 = Fire_3.position;

                GameObject Bullet = ObjectPooling.pool.GetPoolObject_Bullet();
                if (Bullet == null)
                {
                    return;
                }

                Bullet.GetComponent <BulletCtrl> ().Enemy = CloseEn3;

                Bullet.transform.position = FirePos_3;

                Bullet.SetActive(true);
                L3.Play();
                Bullet.GetComponent <Rigidbody> ().velocity = WhereToFireLC3.normalized * bullectLSpeed;

                Bullet.GetComponent <TrailRenderer> ().Clear();
                time = 0;

                TimerOn = false;
            }
        }
        else
        {
            FindEnemyL = false;
        }
    }