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

            PlayerPos1     = FindPlayer().transform.position;
            WhereToFireRC1 = PlayerPos1 - FirePos1.transform.position;
            WhereToFireRC2 = PlayerPos1 - FirePos2.transform.position;
            WhereToFireRC3 = 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);
                R1.Play();

                enemyBullet1.GetComponent <Rigidbody> ().velocity = WhereToFireRC1.normalized * bullectRSpeed;
            }
            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);
                R2.Play();

                enemyBullet2.GetComponent <Rigidbody>().velocity = WhereToFireRC2.normalized * bullectRSpeed;
            }
            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);
                R3.Play();

                enemyBullet3.GetComponent <Rigidbody>().velocity = WhereToFireRC3.normalized * bullectRSpeed;

                time    = 0;
                TimerOn = false;
            }
        }
        else
        {
            FindPlayerR = false;
        }
    }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        if (FindEnemyR)
        {
            Vector3 closeEnemyPos1;
            Vector3 closeEnemyPos2;
            Vector3 closeEnemyPos3;
            if (GameObject.FindGameObjectWithTag("EnemyR") != 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);

                WhereToFireRC1 = closeEnemyPos1 - Fire_1.position;
                WhereToFireRC2 = closeEnemyPos2 - Fire_2.position;
                WhereToFireRC3 = closeEnemyPos3 - Fire_3.position;
            }
            else
            {
                time = 0;
            }
        }

        if (TimerOn)
        {
            time++;
            if (time == reload)
            {
                Vector3 FirePos_1 = Fire_1.position;
                //TempBulletRC1 = Instantiate (BulletRC1, FirePos_1, BulletRC1.transform.rotation) as GameObject;

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

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

                Bullet.transform.position = FirePos_1;


                Bullet.SetActive(true);
                R1.Play();
                Bullet.GetComponent <Rigidbody> ().velocity = WhereToFireRC1.normalized * bullectRSpeed;
                Bullet.GetComponent <TrailRenderer> ().Clear();
            }
            else if (time == reload * 2)
            {
                Vector3 FirePos_2 = Fire_2.position;

                //TempBulletRC2 = Instantiate (BulletRC2, FirePos_2, BulletRC2.transform.rotation);
                GameObject Bullet = ObjectPooling.pool.GetPoolObject_Bullet();
                if (Bullet == null)
                {
                    return;
                }

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

                Bullet.transform.position = FirePos_2;


                Bullet.SetActive(true);
                R2.Play();
                Bullet.GetComponent <Rigidbody> ().velocity = WhereToFireRC2.normalized * bullectRSpeed;
                Bullet.GetComponent <TrailRenderer> ().Clear();
            }
            else if (time == reload * 3)
            {
                Vector3 FirePos_3 = Fire_3.position;
                //TempBulletRC3 = Instantiate (BulletRC3, FirePos_3, BulletRC3.transform.rotation);
                GameObject Bullet = ObjectPooling.pool.GetPoolObject_Bullet();
                if (Bullet == null)
                {
                    return;
                }

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

                Bullet.transform.position = FirePos_3;

                Bullet.SetActive(true);
                R3.Play();
                Bullet.GetComponent <Rigidbody> ().velocity = WhereToFireRC3.normalized * bullectRSpeed;
                Bullet.GetComponent <TrailRenderer> ().Clear();

                time    = 0;
                TimerOn = false;
            }
        }
        else
        {
            FindEnemyR = false;
        }
    }