void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.CompareTag("Pick Up"))
     {
         other.gameObject.SetActive(false);
         count = count + 1;
         SetCountText();
         //health.TakeDamage (10f);
         vida1.TakeDamage(10f);
         elbono.activo = true;
     }
 }
Beispiel #2
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.name == "EnemyColliders")
     {
         if (other.transform.parent.gameObject.GetComponent <Vida>() != null)
         {
             enemyHealth = other.transform.parent.gameObject.GetComponent <Vida>();
             Debug.Log("Enemy name" + other.transform.parent.gameObject.name);
             enemyHealth.TakeDamage(damage);
             Debug.Log("Enemy Hit" + enemyHealth.currentHealth);
         }
     }
 }
Beispiel #3
0
 void OnCollisionEnter(Collision other)
 {
     if (other.gameObject.tag == "Killzone" && !isDead)
     {
         StartCoroutine(_Death());
     }
     else if (other.gameObject.tag == "damageObject")
     {
         vida1.TakeDamage(20);
         this.vida -= 20;
         if (this.vida <= 0)
         {
             StartCoroutine(_Death());
         }
     }
 }
    void OnCollisionEnter(Collision collision)
    {
        GameObject hit    = collision.gameObject;
        Vida       health = hit.GetComponent <Vida>();

        if (collision.relativeVelocity.magnitude > 5)
        {
            Debug.Log("sonidoooooooo");
            fuenteAudio.clip = gunSound;
            fuenteAudio.Play();
        }

        if (health != null)
        {   //fuenteAudio.clip = gunSound;
            health.TakeDamage(10);
        }
        //fuenteAudio.clip = gunSound;
        //fuenteAudio.Play();
        Destroy(gameObject);
    }
Beispiel #5
0
    void Update()
    {
        Vector2 currentPosition = new Vector2(transform.position.x, transform.position.y);
        Vector2 newPosition     = currentPosition + velocity * Time.deltaTime;

        Debug.DrawLine(currentPosition + offset, newPosition + offset, Color.green, 30000000000);

        RaycastHit2D[] hits = Physics2D.LinecastAll(currentPosition + offset, newPosition + offset);

        if (hits.Length == 0)
        {
            Invoke("DestoyProjectile", 2);
        }
        else
        {
            CancelInvoke("DestoyProjectile");
            foreach (RaycastHit2D hit in hits)
            {
                GameObject other = hit.collider.gameObject;
                if (other != player)
                {
                    if (other.gameObject.name == "EnemyColliders")
                    {
                        enemyHealth = other.transform.parent.gameObject.GetComponent <Vida>();
                        if (other.transform.parent.gameObject.GetComponent <Enemies>() != null)
                        {
                            enemyOther = other.transform.parent.gameObject.GetComponent <Enemies>();
                        }
                        else
                        {
                            Boss = other.transform.parent.gameObject.GetComponent <Boss1>();
                        }
                        //realDamage = (iceDamage / enemyHealth.damageReduction);
                        realDamage = iceDamage;
                        if ((other.transform.parent.gameObject.GetComponent <Enemies>() != null && !enemyOther.dead) || (other.transform.parent.gameObject.GetComponent <Boss1>() != null && Boss.vida.currentHealth != 0))
                        {
                            if (gameObject.CompareTag("Iceball"))
                            {
                                if (realDamage > 0 && iceCanDamage)
                                {
                                    if (other.transform.parent.gameObject.GetComponent <Enemies>() != null)
                                    {
                                        enemySpeed       = enemyOther.speed;
                                        enemyOther.speed = (enemyOther.speed / freeze);
                                        Debug.Log("Enemy mv" + enemyOther.speed);
                                    }
                                    enemyHealth.TakeDamage(realDamage);
                                    canHitWall = false;
                                    GameObject explosion = Instantiate(explosionPrefab, transform.position, Quaternion.identity);
                                    Destroy(explosion, 2.3f);

                                    Debug.Log("Damage Dealt: " + realDamage);
                                    Debug.Log(enemyHealth.currentHealth);
                                    Debug.Log(other.name);
                                    StartCoroutine(Freezing());
                                }


                                IEnumerator Freezing()
                                {
                                    iceCanDamage = false;
                                    gameObject.GetComponent <SpriteRenderer>().enabled = false;
                                    yield return(new WaitForSeconds(1));

                                    iceCanDamage = true;
                                    if (other.transform.parent.gameObject.GetComponent <Enemies>() != null)
                                    {
                                        enemyOther.speed = enemySpeed;
                                        Debug.Log("Enemy mv" + enemyOther.speed);
                                    }
                                    Destroy(gameObject);
                                }
                            }
                            else
                            {
                                realDamage = fireDamage;
                                //realDamage = (fireDamage / enemyHealth.damageReduction);
                                enemyHealth.TakeDamage(realDamage);

                                GameObject explosion = Instantiate(explosionPrefab, transform.position, Quaternion.identity);
                                Destroy(gameObject);
                                Destroy(explosion, 2.3f);

                                Debug.Log("Damage Dealt: " + realDamage);
                                Debug.Log(enemyHealth.currentHealth);
                                Debug.Log(other.name);
                            }
                        }
                        break;
                    }
                    if (other.CompareTag("TopWalls"))
                    {
                        if (triggerWall && canHitWall)
                        {
                            GameObject explosion = Instantiate(explosionPrefab, transform.position, Quaternion.identity);
                            Destroy(explosion, 2.3f);
                            Destroy(gameObject);
                            Debug.Log(other.name);
                            break;
                        }
                    }
                    if (canHitWall && (other.CompareTag("BottomWalls") || other.CompareTag("Obstacle")))
                    {
                        GameObject explosion = Instantiate(explosionPrefab, transform.position, Quaternion.identity);
                        Destroy(explosion, 2.3f);
                        Destroy(gameObject);
                        Debug.Log(other.name);
                        break;
                    }
                }
            }
        }
        transform.position = newPosition;
    }
Beispiel #6
0
    void Update()
    {
        Vector2 currentPosition = new Vector2(transform.position.x, transform.position.y);
        Vector2 newPosition     = currentPosition + velocity * Time.deltaTime;

        Debug.DrawLine(currentPosition, newPosition, Color.green, 30000000000);
        RaycastHit2D[] hits = Physics2D.LinecastAll(currentPosition, newPosition);

        if (hits.Length == 0)
        {
            Invoke("DestroyFireRing", 2);
        }
        else
        {
            CancelInvoke("DestoyProjectile");
            foreach (RaycastHit2D hit in hits)
            {
                GameObject other = hit.collider.gameObject;
                if (other != player)
                {
                    if (other.gameObject.name == "EnemyColliders")
                    {
                        enemyScript = other.transform.parent.gameObject.GetComponent <Vida>();
                        if (other.transform.parent.gameObject.GetComponent <Enemies>() != null)
                        {
                            enemyOther = other.transform.parent.gameObject.GetComponent <Enemies>();
                        }
                        else
                        {
                            Boss = other.transform.parent.gameObject.GetComponent <Boss1>();
                        }
                        if ((other.transform.parent.gameObject.GetComponent <Enemies>() != null && !enemyOther.dead))
                        {
                            enemyScript.TakeDamage(damage);
                            Debug.Log(enemyScript.currentHealth);
                            GameObject explosion = Instantiate(explosionPrefab, transform.position, Quaternion.identity);
                            explosion.GetComponent <AudioSource>().volume = 0.2f;
                            Destroy(explosion, 2.3f);
                            Destroy(gameObject);
                            Debug.Log(other.name);
                        }
                        if (other.transform.parent.gameObject.GetComponent <Boss1>() != null)
                        {
                            enemyScript.TakeDamage(damage);
                            Debug.Log(enemyScript.currentHealth);
                            GameObject explosion = Instantiate(explosionPrefab, transform.position, Quaternion.identity);
                            explosion.GetComponent <AudioSource>().volume = 0.2f;
                            Destroy(explosion, 2.3f);
                            Destroy(gameObject);
                            Debug.Log(other.name);
                        }
                        break;
                    }
                    if (other.CompareTag("TopWalls") || other.CompareTag("BottomWalls") || other.CompareTag("Obstacle"))
                    {
                        Destroy(gameObject);
                        GameObject explosion = Instantiate(explosionPrefab, transform.position, Quaternion.identity);
                        explosion.GetComponent <AudioSource>().volume = 0.2f;
                        Destroy(explosion, 2.3f);
                        Debug.Log(other.name);
                        break;
                    }
                }
            }
        }

        transform.position = newPosition;
    }