Ejemplo n.º 1
0
    void FireEMP()
    {
        if (empCount > 0)
        {
            empCount--;

            SoundManagerScript.Instance.StopAllCoroutines();

            SoundManagerScript.Instance.StartCoroutine(SoundManagerScript.Instance.BGMFadeVolume(0f, 0.1f, 0f));

            SoundManagerScript.Instance.PlaySFX(AudioClipID.SFX_EMP);

            PlayerManagerScript.instance.EMPCount.text = "X : " + empCount.ToString();

            for (int i = 0; i < 3; i++)
            {
                GameObject         newemp    = Instantiate(empGO, transform.position, Quaternion.identity) as GameObject;
                BoomParticleScript empScript = newemp.GetComponent <BoomParticleScript>();

                if (empScript != null)
                {
                    empScript.emp = true;
                    empScript.ExpandBoom(4f - i - 0.5f, 0f, 0f, 4f / (i + 1));
                    empScript.GetComponent <SpriteRenderer>().color = Color.cyan;
                }
            }

            SoundManagerScript.Instance.StartCoroutine(SoundManagerScript.Instance.BGMFadeVolume(0.1f, 1f, 2f));
        }
    }
    IEnumerator ClusterBoom(float size, float speed, int min, int max, float delay)
    {
        yield return(new WaitForSeconds(delay));

        //List<GameObject> particleList = new List<GameObject>();

        Debug.Log("min : " + min);
        Debug.Log("max : " + max);


        int num = Random.Range(min, max + 1);
        int i   = 0;

        GameObject         newpart    = Instantiate(boomParticle, this.transform.position, Quaternion.identity) as GameObject;
        BoomParticleScript partscript = newpart.GetComponent <BoomParticleScript>();

        if (partscript != null)
        {
            partscript.expandSize = size;
        }

//		while(i < num)
//		{
//			Transform pos = this.transform;
//			pos.Rotate(0f, 0f, 360f / num * i);
//
//			GameObject newpart = Instantiate(boomParticle, this.transform.position, pos.rotation) as GameObject;
//			BoomParticleScript partscript = newpart.GetComponent<BoomParticleScript>();
//
//			//particleList.Add(newpart);
//
//			newpart.transform.parent = this.transform;
//			//newpart.transform.Rotate(0f, 0f, 360f/ (float)i);
//			newpart.transform.localScale = new Vector3(size, size, 1f);
//
//			if(partscript != null)
//			{
//				partscript.moveSpeed = speed;
//
//				Debug.Log(partscript.moveSpeed);
//			}
//
//			i++;
//		}
    }
Ejemplo n.º 3
0
    public IEnumerator HitEMP()
    {
        for (int i = 0; i < 5; i++)
        {
            yield return(new WaitForSeconds(0.5f * i));

            float randX = Random.Range(transform.position.x - rend.bounds.extents.x, transform.position.x + rend.bounds.extents.x);
            float randY = Random.Range(transform.position.y - rend.bounds.extents.y, transform.position.y + rend.bounds.extents.y);

            Vector3 vect = new Vector3(randX, randY, 0f);

            GameObject go = Instantiate(boomParticle, vect, Quaternion.identity);

            go.transform.parent = transform;

            BoomParticleScript goScript = go.GetComponent <BoomParticleScript>();
            goScript.GetComponent <SpriteRenderer>().color = Color.cyan;
            goScript.ExpandBoom(0.2f, 0f, 0f, 2.5f);
            goScript.coll.enabled = false;
        }
    }
Ejemplo n.º 4
0
    public void TakeDamage(float damage)
    {
        flashTime = 0.25f;

        if (!damageFlash)
        {
            damageFlash = true;
        }

        if ((health - damage) < 0f)
        {
            float temp = health - damage;

            health = 0f;
            WaveManagerScript.instance.liveEnemyHealth -= (damage - Mathf.Abs(temp));
        }
        else
        {
            WaveManagerScript.instance.liveEnemyHealth -= damage;
            health -= damage;
        }

        if (health <= 0f)
        {
            WaveManagerScript.instance.liveEnemyList.Remove(this);

            GameObject go = Instantiate(boomParticle, transform.position, Quaternion.identity);

            BoomParticleScript goScript = go.GetComponent <BoomParticleScript>();
            goScript.GetComponent <SpriteRenderer>().color = Color.red;
            goScript.ExpandBoom(0.75f, 0f, 0f, 2.5f);
            goScript.coll.enabled = false;

            Destroy(gameObject);

            SoundManagerScript.Instance.PlaySFX(AudioClipID.SFX_DEATH);
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (PauseManagerScript.instance.isPaused)
        {
            return;
        }

        colorFlashTimer -= Time.deltaTime;

        if (bulletType == CannonType.CLUSTERNADE || bulletType == CannonType.CLUSTERCHILD)
        {
            if (colorFlashTimer <= colorFlashDuration / 2)
            {
                rend.color = Color.red;

                if (colorFlashTimer <= 0f)
                {
                    colorFlashTimer = colorFlashDuration;
                }
            }
            else if (colorFlashTimer <= colorFlashDuration)
            {
                rend.color = Color.yellow;
            }
        }
        else if (bulletType == CannonType.BOOMERANG || bulletType == CannonType.BOOMERANGCHILD)
        {
            if (colorFlashTimer <= colorFlashDuration / 2)
            {
                rend.color = Color.cyan;

                if (colorFlashTimer <= 0f)
                {
                    colorFlashTimer = colorFlashDuration;
                }
            }
            else if (colorFlashTimer <= colorFlashDuration)
            {
                rend.color = Color.yellow;
            }
        }

        if (bulletType == CannonType.CLUSTERCHILD)
        {
            if (bulletSpeed < 0f)
            {
                bulletSpeed = 0f;

                GameObject         newpart    = Instantiate(boomParticle, this.transform.position, Quaternion.identity) as GameObject;
                BoomParticleScript partscript = newpart.GetComponent <BoomParticleScript>();

                if (partscript != null)
                {
                    partscript.ExpandBoom(0.5f, 0.5f, damage, 1f);
                    Destroy(gameObject, 0.5f);
                }
            }
            else if (bulletSpeed > 0f)
            {
                bulletSpeed -= Time.deltaTime * 100f;
            }
        }
        else if (bulletType == CannonType.BOOMERANG)
        {
            if (!coll.enabled)
            {
                transform.Rotate(0f, 0f, 5f);
            }
        }

        transform.Translate(Vector3.right * Time.deltaTime * bulletSpeed);
    }
//	void BulletHit(EnemyScript other)
//	{
//		if(bulletType == CannonType.NORMAL)
//		{
//
//		}
//	}

    void OnTriggerEnter2D(Collider2D other)
    {
        if (!other.CompareTag("Player") && !other.CompareTag("EnemyBullet"))
        {
            Debug.Log("Cannon Hit");

            EnemyScript enemy = other.GetComponent <EnemyScript>();

            if (bulletType == CannonType.NORMAL)
            {
                if (enemy != null)
                {
                    enemy.TakeDamage(damage);
                }

                Destroy(gameObject);
            }
            else if (bulletType == CannonType.SNIPER)
            {
                if (enemy != null)
                {
                    enemy.TakeDamage(damage);
                }

                Destroy(gameObject);
            }
            else if (bulletType == CannonType.SHOTGUN)
            {
                if (enemy != null)
                {
                    enemy.TakeDamage(damage);
                }

                Destroy(gameObject);
            }
            else if (bulletType == CannonType.CLUSTERNADE)
            {
                bulletType = CannonType.NORMAL;

                for (int i = 0; i < 6; i++)
                {
                    Transform pos = transform;

                    pos.Rotate(0f, 0f, 360f / 6f * i);

                    GameObject newbullet = Instantiate(this.gameObject, transform.position, pos.rotation);

                    CannonBulletScript bulletscript = newbullet.GetComponent <CannonBulletScript>();
                    bulletscript.bulletType = CannonType.CLUSTERCHILD;
                    bulletscript.damage     = damage;
                }

                if (enemy != null)
                {
                    enemy.TakeDamage(damage);
                }

                Destroy(gameObject);
            }
            else if (bulletType == CannonType.BOOMERANG)
            {
                Debug.Log(other.name);

                coll.enabled = false;
                rend.enabled = false;

                GameObject newbullet = Instantiate(this.gameObject, transform.position, transform.rotation);

                CannonBulletScript bulletscript = newbullet.GetComponent <CannonBulletScript>();
                bulletscript.bulletType   = CannonType.BOOMERANGCHILD;
                bulletscript.coll.enabled = true;
                bulletscript.rend.enabled = true;
                bulletscript.bulletSpeed  = bulletSpeed * 0.005f;
                bulletscript.damage       = 20f;

                newbullet.transform.parent = this.transform;

                if (enemy != null)
                {
                    enemy.TakeDamage(damage);
                }

                Destroy(gameObject, 5f);
            }
            else if (bulletType == CannonType.BOOMERANGCHILD)
            {
                if (enemy != null)
                {
                    enemy.TakeDamage(damage);
                }
            }
            else if (bulletType == CannonType.CLUSTERCHILD)
            {
                bulletSpeed = 0f;

                Debug.Log(other.name);

                if (enemy != null)
                {
                    enemy.TakeDamage(damage);

                    GameObject         newpart    = Instantiate(boomParticle, this.transform.position, Quaternion.identity) as GameObject;
                    BoomParticleScript partscript = newpart.GetComponent <BoomParticleScript>();

                    if (partscript != null)
                    {
                        partscript.ExpandBoom(1f, 0f, damage, 1f);
                        Destroy(gameObject, 0.2f);
                    }


                    //StartCoroutine(ClusterBoom(1.2f, 10f, 12, 15, 0.2f));
                }
                else
                {
                    GameObject         newpart    = Instantiate(boomParticle, this.transform.position, Quaternion.identity) as GameObject;
                    BoomParticleScript partscript = newpart.GetComponent <BoomParticleScript>();

                    if (partscript != null)
                    {
                        partscript.ExpandBoom(0.5f, 0.5f, damage, 1f);
                        Destroy(gameObject, 0.5f);
                    }

                    //StartCoroutine(ClusterBoom(0.8f, 5f, 8, 10, 0.5f));
                }
            }


            //BulletHit();
        }
    }