Exemple #1
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.tag == "EnemyBullet")
     {
         BulletClass bullet = collision.GetComponent <BulletClass>();
         if (m_damage)
         {
             return;
         }
         m_life = m_life - bullet.m_power;
         StartCoroutine("DamageTimer");
     }
     if (collision.tag == "Enemy")
     {
         Enemy enemy = collision.GetComponent <Enemy>();
         if (m_damage)
         {
             return;
         }
         m_life = m_life - enemy.m_power;
         StartCoroutine("DamageTimer");
     }
     if (m_life <= 0)
     {
         Destroy(gameObject);
     }
 }
Exemple #2
0
    public void Shoot(GameObject bullet, Vector3 coords, float destroyTime, float angle)
    {
        coords = new Vector3(coords.x, coords.y, coords.z - 0.1f);
        BulletClass bullets = Instantiate(bullet, coords, Quaternion.Euler(0, angle, 0)).GetComponent <BulletClass>();

        bullets.Initialize(-10f);
        bullets.gameObject.tag = "BossBullet";
        Destroy(bullets.gameObject, destroyTime);
    }
Exemple #3
0
    public virtual void Shoot(GameObject bullet, Vector3 coords, float destroyTime)
    {
        coords = new Vector3(coords.x, coords.y, coords.z - 0.1f);
        BulletClass bullets = Instantiate(bullet, coords, Quaternion.identity).GetComponent <BulletClass>();

        bullets.Initialize(-10f);
        bullets.gameObject.tag = "EnemyBullet";
        Destroy(bullets.gameObject, destroyTime);
    }
    public void Shoots(GameObject bullet, Vector3 coords, float destroyTime, float angle)
    {
        coords = new Vector3(coords.x, coords.y, coords.z - 0.1f);
        BulletClass bullets = Instantiate(bullet, coords, Quaternion.Euler(0, angle, 0)).GetComponent <BulletClass>();

        bullets.Initialize(10f);
        bullets.gameObject.tag = "Bullet";
        bullets.GetComponent <MeshRenderer>().material.color = Color.red;
        bullets.explosion = explosionObj;
        Destroy(bullets.gameObject, destroyTime);
    }
Exemple #5
0
    // Start is called before the first frame update
    public BulletPoolManager(GameObject bulletprefab)
    {
        bullet = bulletprefab;
        for (int i = 0; i < bulletamount; i++)
        {
            BulletClass temp = new BulletClass(currentbullets, MonoBehaviour.Instantiate(bullet), false);
            currentbullets++;
            temp.obj.name = temp.Tag.ToString();
            Bullets.Add(temp);
        }

        // TODO: add a series of bullets to the Bullet Pool
    }
Exemple #6
0
    //public Rigidbody2D m_rb = null;

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag == "PlayerBullet")
        {
            BulletClass bullet = collision.GetComponent <BulletClass>();
            m_life = m_life - bullet.m_power;

            if (m_life <= 0)
            {
                Destroy(gameObject);
            }
        }
    }
Exemple #7
0
    void OnTriggerEnter(Collider col)
    {
        if (col.gameObject.tag == "Bullet")
        {
            BulletClass bullet = col.gameObject.GetComponent <BulletClass>();

            if (bullet.enemy.gameObject == this.gameObject)
            {
                SubstractHealth(bullet.tower.damage);

                if (bullet.tower.slow)
                {
                    StartCoroutine("Freeze", bullet.tower.abilityPower);
                }

                if (bullet.tower.poison)
                {
                    poisonTime = Time.time;
                    StartCoroutine("Poison", bullet.tower.abilityPower);
                }

                if (bullet.tower.splash)
                {
                    hitColliders = Physics.OverlapSphere(myTransform.position, 2.0f);
                    foreach (Collider enemyInSplashRange in hitColliders)
                    {
                        Enemy enemy = enemyInSplashRange.GetComponent <Enemy>();
                        if (enemyInSplashRange && enemyInSplashRange.tag == "Enemy" && enemyInSplashRange.gameObject != this.gameObject && !enemy.air)
                        {
                            Debug.Log((int)(bullet.tower.damage * bullet.tower.abilityPower));
                            enemy.SubstractHealth((int)(bullet.tower.damage * bullet.tower.abilityPower));
                        }
                    }
                }
            }
        }

        if (col.gameObject.tag == "Final")
        {
            Destroy(gameObject);
            PlayerScript.instance.LoseLive(lifeCost);
            LevelClass.instance.CheckWin();

            GameObject[] allTowers = GameObject.FindGameObjectsWithTag("Tower");
            foreach (GameObject tower in allTowers)
            {
                tower.GetComponent <TowerClass>().RemoveEnemyFromTargets(this);
            }
        }
    }
Exemple #8
0
        /// <summary>
        /// Make a pretty explosion on clients
        /// </summary>
        public void DestroyBullet(GameObject destoryObj, BulletClass explosionClass)
        {
            int            ClassIndex = (int)explosionClass;
            ExplosionCache pool       = m_ExplosionCache[ClassIndex];

            if (pool != null)
            {
                destoryObj.SetActive(false);
            }
            else
            {
                MonoBehaviour.Destroy(destoryObj);
            }
        }
Exemple #9
0
        /// <summary>
        /// 实例化子弹对象
        /// </summary>
        public GameObject CreateVisualBullet(Vector3 pos, Vector3 dir, float speed, BulletClass explosionClass)
        {
            GameObject     spawnedEffect = null;
            int            ClassIndex    = (int)explosionClass;
            ExplosionCache pool          = m_ExplosionCache[ClassIndex];

            switch (explosionClass)
            {
            case BulletClass.FiringExplosion:
                spawnedEffect = pool.NextGameObject();
                break;

            case BulletClass.ClusterExplosion:
                spawnedEffect = pool.NextGameObject();
                break;

            case BulletClass.PulseExplosion:
                spawnedEffect = pool.NextGameObject();
                break;
            }
            return(spawnedEffect);
        }
Exemple #10
0
    private void OnCollisionStay2D(Collision2D collision)
    {
        if ((canParry && !canShoot) &&
            collision.gameObject.tag.Equals("Bullet") &&
            collision.gameObject.GetComponent <BulletClass>().Target.Equals("Player"))
        {
            BulletClass bullet    = collision.gameObject.GetComponent <BulletClass>();
            Vector2     direction = (((Vector2)bullet.transform.position + Vector2.one) - (Vector2)bullet.transform.position).normalized;

            if (bullet.Shooter != null)
            {
                direction = bullet.Shooter.transform.position - bullet.transform.position;
            }
            bullet.Direction = direction.normalized;

            Vector3 difference = transform.parent.position - transform.position;
            float   rotationZ  = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
            bullet.transform.rotation = Quaternion.Euler(bullet.transform.rotation.x, bullet.transform.rotation.y, rotationZ);

            bullet.Speed  = 1.5f;
            bullet.Target = "Enemy";
            bullet.Damage = 2;
        }
    }
    // Use this for initialization
    protected virtual void Start()
    {
        _parameter += _parameter + GetComponent <Display_Parameter>();
        //_battleSystem.Pararray[_id[1], _id[0]] += _battleSystem.Pararray[_id[1], _id[0]] + GetComponent<Display_Parameter>();

        if (GetComponent <Buff_HPSP>())
        {
            SendHP = GetComponent <Buff_HPSP>();
        }
        if (GetComponent <Buff_Others>())
        {
            SendO = GetComponent <Buff_Others>();
        }

        StartCoroutine("ApplyReceiveBuff");                //バフ処理

        if (Bullet && Bullet.GetComponent <Bullet_Sord>()) //近接攻撃があれば
        {
            SordB = Instantiate(Bullet, transform);
            SordB.SetActive(false);
        }
        else if (SPBullet && SPBullet.GetComponent <Bullet_Sord>())
        {
            SordB2 = Instantiate(SPBullet, transform);
            SordB2.SetActive(false);
        }

        //事前生産
        if (Bullet)
        {
            BulletArray[0] = new GameObject[MakeNum[0]];
            //弾
            for (int j = 0; j < BulletArray[0].Length; j++)            //とりま10
            {
                BulletArray[0][j] = Instantiate(Bullet, _battleSystem.transform) as GameObject;
                BulletClass b_bullet = BulletArray[0][j].GetComponent <BulletClass>();
                b_bullet.ATTACKER = this;
                b_bullet.POWER    = _parameter.DISTANCE;
                b_bullet.SYS      = _battleSystem;
                if (SendHP)
                {
                    b_bullet.BUFF1 = SendHP;
                }
                if (SendO)
                {
                    b_bullet.BUFF2 = SendO;
                }
                //ミサイルはしばらく封印
                //if (BulletArray[0][j].GetComponent<Bullet_Missile>() && TargetObj != null)
                //{
                //	BulletArray[0][j].GetComponent<Bullet_Missile>().Missile_TARGET = TargetObj;
                //}
                BulletArray[0][j].SetActive(false);
            }
        }
        if (SPBullet)
        {
            BulletArray[1] = new GameObject[MakeNum[1]];
            //弾
            for (int j = 0; j < BulletArray[1].Length; j++)            //とりま10
            {
                BulletArray[1][j] = Instantiate(SPBullet, _battleSystem.transform) as GameObject;
                BulletClass b_bullet = BulletArray[1][j].GetComponent <BulletClass>();
                b_bullet.ATTACKER = this;
                b_bullet.POWER    = _parameter.DISTANCE;
                b_bullet.SYS      = _battleSystem;
                if (SendHP)
                {
                    b_bullet.BUFF1 = SendHP;
                }
                if (SendO)
                {
                    b_bullet.BUFF2 = SendO;
                }
                //if (BulletArray[1][j].GetComponent<Bullet_Missile>() && TargetObj != null)
                //{
                //	BulletArray[1][j].GetComponent<Bullet_Missile>().Missile_TARGET = TargetObj;
                //}
                BulletArray[1][j].SetActive(false);
            }
        }
    }