Exemplo n.º 1
0
    public virtual void StartShooting()
    {
        Timer += Time.deltaTime;
        if (Timer > FireRate)
        {
            //Instantiate an object and set their velocity to the calculated value of where the enemy they're shooting will be
            GameObject InstantiatedBullet;
            InstantiatedBullet = Instantiate(Bullet, new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, 0f), transform.rotation);
            Bullet      bullet = InstantiatedBullet.GetComponent <Bullet> ();
            Rigidbody2D body   = EnemyBeingShot.GetComponent <Rigidbody2D> ();
            //Draw a vector from the tower to the enemy
            Vector2 Position       = EnemyBeingShot.transform.position;
            Vector3 FuturePosition = new Vector2(Position.x, Position.y) + body.velocity * Time.deltaTime;
            Vector2 VectorToEnemy  = FuturePosition - transform.position;

            //Normalize the vector from the tower to the enemy and apply the bullet speed to it
            InstantiatedBullet.GetComponent <Rigidbody2D>().velocity = VectorToEnemy.normalized * BulletSpeed;
            Timer = 0;
        }
    }
    void Shoot(int switches)
    {
        GameObject InstantiatedBullet;

        parentAnim.SetTrigger("Shoot");
        if (parent.name == "TowerBase(Clone)")
        {
            if (level >= 2)
            {
                if (switches == 1)
                {
                    InstantiatedBullet = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity);
                    InstantiatedBullet.GetComponent <BulletController>().bulletDamage = damage;
                    InstantiatedBullet.GetComponent <BulletController>().Direction    = new Vector3(1, 1, 0);

                    InstantiatedBullet = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity);
                    InstantiatedBullet.GetComponent <BulletController>().bulletDamage = damage;
                    InstantiatedBullet.GetComponent <BulletController>().Direction    = new Vector3(-1, -1, 0);

                    InstantiatedBullet = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity);
                    InstantiatedBullet.GetComponent <BulletController>().bulletDamage = damage;
                    InstantiatedBullet.GetComponent <BulletController>().Direction    = new Vector3(1, -1, 0);

                    InstantiatedBullet = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity);
                    InstantiatedBullet.GetComponent <BulletController>().bulletDamage = damage;
                    InstantiatedBullet.GetComponent <BulletController>().Direction    = new Vector3(-1, 1, 0);
                }
                else
                {
                    InstantiatedBullet = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity);
                    InstantiatedBullet.GetComponent <BulletController>().bulletDamage = damage;
                    InstantiatedBullet.GetComponent <BulletController>().Direction    = new Vector3(0, 1, 0);

                    InstantiatedBullet = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity);
                    InstantiatedBullet.GetComponent <BulletController>().bulletDamage = damage;
                    InstantiatedBullet.GetComponent <BulletController>().Direction    = new Vector3(0, -1, 0);

                    InstantiatedBullet = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity);
                    InstantiatedBullet.GetComponent <BulletController>().bulletDamage = damage;
                    InstantiatedBullet.GetComponent <BulletController>().Direction    = new Vector3(1, 0, 0);

                    InstantiatedBullet = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity);
                    InstantiatedBullet.GetComponent <BulletController>().bulletDamage = damage;
                    InstantiatedBullet.GetComponent <BulletController>().Direction    = new Vector3(-1, 0, 0);
                }
            }
            else
            {
                InstantiatedBullet = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity);
                InstantiatedBullet.GetComponent <BulletController>().bulletDamage = damage;
                InstantiatedBullet.GetComponent <BulletController>().Direction    = new Vector3(0, 1, 0);

                InstantiatedBullet = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity);
                InstantiatedBullet.GetComponent <BulletController>().bulletDamage = damage;
                InstantiatedBullet.GetComponent <BulletController>().Direction    = new Vector3(0, -1, 0);

                InstantiatedBullet = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity);
                InstantiatedBullet.GetComponent <BulletController>().bulletDamage = damage;
                InstantiatedBullet.GetComponent <BulletController>().Direction    = new Vector3(1, 0, 0);

                InstantiatedBullet = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity);
                InstantiatedBullet.GetComponent <BulletController>().bulletDamage = damage;
                InstantiatedBullet.GetComponent <BulletController>().Direction    = new Vector3(-1, 0, 0);
            }
        }
        if (parent.name == "Cannons(Clone)")
        {
            InstantiatedBullet = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity);
            InstantiatedBullet.GetComponent <BulletController>().bulletDamage = damage;
            InstantiatedBullet.GetComponent <BulletController>().Direction    = new Vector3(0, 1, 0);
        }
        if (parent.name == "Flame_Tower_1(Clone)")
        {
            //add loop here
            //for(int i=0; i<)

            InstantiatedBullet = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity);
            InstantiatedBullet.GetComponent <BulletController>().bulletDamage = damage;
            InstantiatedBullet.GetComponent <BulletController>().Direction    = new Vector3(0, 1, 0);

            InstantiatedBullet = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity);
            InstantiatedBullet.GetComponent <BulletController>().bulletDamage = damage;
            InstantiatedBullet.GetComponent <BulletController>().Direction    = new Vector3(0, -1, 0);

            InstantiatedBullet = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity);
            InstantiatedBullet.GetComponent <BulletController>().bulletDamage = damage;
            InstantiatedBullet.GetComponent <BulletController>().Direction    = new Vector3(1, 0, 0);

            InstantiatedBullet = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity);
            InstantiatedBullet.GetComponent <BulletController>().bulletDamage = damage;
            InstantiatedBullet.GetComponent <BulletController>().Direction    = new Vector3(-1, 0, 0);

            InstantiatedBullet = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity);
            InstantiatedBullet.GetComponent <BulletController>().bulletDamage = damage;
            InstantiatedBullet.GetComponent <BulletController>().Direction    = new Vector3(1, 1, 0);

            InstantiatedBullet = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity);
            InstantiatedBullet.GetComponent <BulletController>().bulletDamage = damage;
            InstantiatedBullet.GetComponent <BulletController>().Direction    = new Vector3(1, -1, 0);

            InstantiatedBullet = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity);
            InstantiatedBullet.GetComponent <BulletController>().bulletDamage = damage;
            InstantiatedBullet.GetComponent <BulletController>().Direction    = new Vector3(-1, 1, 0);

            InstantiatedBullet = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity);
            InstantiatedBullet.GetComponent <BulletController>().bulletDamage = damage;
            InstantiatedBullet.GetComponent <BulletController>().Direction    = new Vector3(-1, -1, 0);
        }
        if (parent.name == "Lightning_Tower(Clone)")
        {
            foreach (GameObject enemy in EnemiesInRange)
            {
                Instantiate(lightningCloud, new Vector3(enemy.transform.position.x, enemy.transform.position.y + 1, enemy.transform.position.z), Quaternion.identity);
                InstantiatedBullet = Instantiate(Lightningreal, new Vector3(enemy.transform.position.x, enemy.transform.position.y, enemy.transform.position.z), Quaternion.identity);
                InstantiatedBullet.GetComponent <BulletController>().bulletDamage = 2 * damageMultiplier;
            }
        }
        if (parent.name == "Harpoon_Launcher(Clone)")
        {
            InstantiatedBullet = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity);
            InstantiatedBullet.transform.eulerAngles = new Vector3(0, 0, Roundangle - 90);
            InstantiatedBullet.GetComponent <BulletController>().bulletDamage = damage;
            //InstantiatedBullet.GetComponent<BulletController>().Direction = new Vector3(-1, 1, 0);
        }
    }