예제 #1
0
    // Update is called once per frame
    void Update()
    {
        if (shootTimer + 4f < Time.time)
        {
            GameObject Clone = PoolScript.CheckForInactiveEnemyBullet();

            if (Clone == null)
            {
                Clone = (GameObject)Instantiate(bullet, new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, 0), Quaternion.identity);
                PoolScript.enemyBulletList.Add(Clone);
            }
            else
            {
                Clone.transform.position = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, 0);
                Clone.SetActive(true);
            }

            bulDirection = new Vector3(-.4f, -.4f, 0);

            //print ("neg neg" + bulDirection);

            Clone.GetComponent <EnemyBulletScript> ().targetPos = bulDirection;



            Clone = PoolScript.CheckForInactiveEnemyBullet();

            if (Clone == null)
            {
                Clone = (GameObject)Instantiate(bullet, new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, 0), Quaternion.identity);
                PoolScript.enemyBulletList.Add(Clone);
            }
            else
            {
                Clone.transform.position = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, 0);
                Clone.SetActive(true);
            }
            bulDirection = new Vector3(.4f, .4f, 0);
            //print ("pos pos" + bulDirection);

            Clone.GetComponent <EnemyBulletScript> ().targetPos = bulDirection;



            Clone = PoolScript.CheckForInactiveEnemyBullet();

            if (Clone == null)
            {
                Clone = (GameObject)Instantiate(bullet, new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, 0), Quaternion.identity);
                PoolScript.enemyBulletList.Add(Clone);
            }
            else
            {
                Clone.transform.position = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, 0);
                Clone.SetActive(true);
            }

            bulDirection = new Vector3(-.4f, .4f, 0);
            //print ("neg pos"+bulDirection);

            Clone.GetComponent <EnemyBulletScript> ().targetPos = bulDirection;



            Clone = PoolScript.CheckForInactiveEnemyBullet();

            if (Clone == null)
            {
                Clone = (GameObject)Instantiate(bullet, new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, 0), Quaternion.identity);
                PoolScript.enemyBulletList.Add(Clone);
            }
            else
            {
                Clone.transform.position = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, 0);
                Clone.SetActive(true);
            }

            bulDirection = new Vector3(.4f, -.4f, 0);
            //print ("pos neg" + bulDirection);

            Clone.GetComponent <EnemyBulletScript> ().targetPos = bulDirection;

            shootTimer = Time.time;
        }

        //delete here
        if (enemyHealth <= 0)
        {
            dropPowerupScript.location = transform.position;
            dropPowerupScript.RNG();
            enemyHealth = 3;
            gameObject.SetActive(false);
        }
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        //ENEMY PATHING
        //Straight down
        if (pathNum == 1)
        {
            gameObject.transform.position = new Vector2(transform.position.x, transform.position.y - speed * Time.deltaTime);
        }

        //V shaped from top
        if (pathNum == 2)
        {
            if (transform.position.x > 0f)
            {
                transform.position = new Vector2(transform.position.x - speed * Time.deltaTime * 2, transform.position.y - speed * Time.deltaTime);
            }
            if (transform.position.x <= 0f)
            {
                transform.position = new Vector2(transform.position.x - speed * Time.deltaTime * 2, transform.position.y + speed * Time.deltaTime);
                if (transform.position.x < -20)
                {
                    gameObject.SetActive(false);
                }
            }
        }
        //top right L to the left
        if (pathNum == 3)
        {
            if (transform.position.y > 0)
            {
                transform.position = new Vector2(transform.position.x, transform.position.y - speed * Time.deltaTime);
            }
            if (transform.position.y <= 0)
            {
                transform.position = new Vector2(transform.position.x - speed * Time.deltaTime, transform.position.y);
                if (transform.position.x < -20)
                {
                    gameObject.SetActive(false);
                }
            }
        }
        //bot left L to the right
        if (pathNum == 4)
        {
            if (transform.position.y < 0)
            {
                transform.position = new Vector2(transform.position.x, transform.position.y + speed * Time.deltaTime);
            }
            if (transform.position.y >= 0)
            {
                transform.position = new Vector2(transform.position.x + speed * Time.deltaTime, transform.position.y);
                if (transform.position.x > 20)
                {
                    gameObject.SetActive(false);
                }
            }
        }
        //top left to botright
        if (pathNum == 5)
        {
            transform.position = new Vector2(transform.position.x + speed * Time.deltaTime * 1.5f, transform.position.y - speed * Time.deltaTime);
        }
        //bot right to top left
        if (pathNum == 6)
        {
            transform.position = new Vector2(transform.position.x - speed * Time.deltaTime * 1.5f, transform.position.y + speed * Time.deltaTime);
        }
        //top right to bot left
        if (pathNum == 7)
        {
            transform.position = new Vector2(transform.position.x - speed * Time.deltaTime * 1.5f, transform.position.y - speed * Time.deltaTime);
        }
        //bot left to top right
        if (pathNum == 8)
        {
            transform.position = new Vector2(transform.position.x + speed * Time.deltaTime * 1.5f, transform.position.y + speed * Time.deltaTime);
        }


        gameObject.transform.Rotate(new Vector3(0, 0, rotationSpeed));

        //ENEMY SHOOTING
        if (shootTimer + 2.25f < Time.time && canIShoot)
        {
            for (int i = 0; i < 3; i++)
            {
                GameObject Clone = PoolScript.CheckForInactiveEnemyBullet();
                if (Clone == null)
                {
                    Clone = (GameObject)Instantiate(bullet, new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, 0), Quaternion.identity);
                }
                else
                {
                    Clone.transform.position = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, 0);
                    Clone.SetActive(true);
                }
                //GameObject Clone = (GameObject)Instantiate (bullet, new Vector3 (gameObject.transform.position.x, gameObject.transform.position.y, 0), Quaternion.identity);
                if (i == 0)
                {
                    //bullet.transform.LookAt(corner1.transform);
                    bulDirection = (corner1.transform.position - transform.position).normalized;
                    //print (bulDirection);
                    Clone.GetComponent <EnemyBulletScript> ().targetPos = bulDirection;
                }
                else if (i == 1)
                {
                    //bullet.transform.LookAt(corner2.transform);
                    //bullet.GetComponent<EnemyBulletScript>().targetPos = corner2.transform.position;
                    bulDirection = (corner2.transform.position - transform.position).normalized;
                    //print (bulDirection);
                    Clone.GetComponent <EnemyBulletScript> ().targetPos = bulDirection;
                }
                else if (i == 2)
                {
                    //bullet.transform.LookAt(corner3.transform);
                    //bullet.GetComponent<EnemyBulletScript>().targetPos = corner3.transform.position;
                    //bullet.GetComponent<EnemyBulletScript> ().targetPos.x = bullet.GetComponent<EnemyBulletScript> ().targetPos.x * -1;
                    //bullet.GetComponent<EnemyBulletScript> ().speed = -bullet.GetComponent<EnemyBulletScript> ().speed;

                    bulDirection = (corner3.transform.position - transform.position).normalized;
                    //print (bulDirection);
                    Clone.GetComponent <EnemyBulletScript> ().targetPos = bulDirection;
                }
            }

            shootTimer = Time.time;
        }

        /*if (((Time.time-TimeSpawned)+1.6)%1.6 == 0) {
         *      canIShoot = true;
         * }*/


        //DESTROY CHECKS
        if (enemyHealth <= 0)
        {
            dropPowerupScript.location = transform.position;
            dropPowerupScript.RNG();
            enemyHealth = 3;
            gameObject.SetActive(false);
        }

        if (transform.position.y < -10f)
        {
            gameObject.SetActive(false);
        }
    }