Exemplo n.º 1
0
        void OnCollisionEnter2D(Collision2D collision)
        {
            if (collision.transform.gameObject == this.Player)
            {
                Physics2D.IgnoreCollision(GetComponent <BoxCollider2D>(), collision.collider);
            }

            string tag = collision.collider.tag;

            if (tag == "TerrainObject")
            {
                Physics2D.IgnoreCollision(GetComponent <BoxCollider2D>(), collision.collider);
                Terrain2 t   = collision.gameObject.GetComponent <Terrain2>();
                float    tmp = destructionCircle.radius;
                destructionCircle.radius = radius;
                t.DestroyGround(destructionCircle);
                destructionCircle.radius = tmp;
            }
            else if (tag.Contains("Player"))
            {
                int          id     = collision.collider.gameObject.GetInstanceID();
                GameObject[] totems = GameObject.FindGameObjectsWithTag(tag.Replace("Module", ""));
                foreach (GameObject g in totems)
                {
                    Totem totem = g.GetComponent <Totem>();
                    foreach (GameObject mod in totem.Modulos)
                    {
                        if (mod.GetInstanceID() == id)
                        {
                            if (totem.IgluActivado() && (mod.GetInstanceID() == totem.GetIDModuloProtegidoIglu()))
                            {
                                Iglu ig = totem.GetComponentInChildren <Iglu>();
                                ig.IncNumeroUsos();
                                Destroy(this.gameObject);
                            }
                            else
                            {
                                totem.SendMessage("Damage", new HealthEvent(gameObject, damage));
                                totem.DecreaseVida();
                            }
                        }
                    }
                }
            }

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

            Destroy(executeDeathExplosion, executeDeathExplosion.GetComponent <AudioSource>().clip.length);

            Destroy(this.gameObject);
        }
Exemplo n.º 2
0
        void OnCollisionEnter2D(Collision2D collision)
        {
            if (collision.transform.gameObject == this.Player)
            {
                Physics2D.IgnoreCollision(GetComponent <BoxCollider2D>(), collision.collider);
            }

            string tag = collision.collider.tag;

            if (tag == "TerrainObject")
            {
                if (!ignore)
                {
                    Invoke("Explosion", 2);
                }
                ignore = true;
            }
            else if (tag.Contains("Player"))
            {
                int          id     = collision.collider.gameObject.GetInstanceID();
                GameObject[] totems = GameObject.FindGameObjectsWithTag(tag.Replace("Module", ""));
                foreach (GameObject g in totems)
                {
                    Totem totem = g.GetComponent <Totem>();
                    foreach (GameObject mod in totem.Modulos)
                    {
                        if (mod.GetInstanceID() == id)
                        {
                            if (totem.IgluActivado() && (mod.GetInstanceID() == totem.GetIDModuloProtegidoIglu()))
                            {
                                Iglu ig = totem.GetComponentInChildren <Iglu>();
                                ig.IncNumeroUsos();
                                Destroy(this.gameObject);
                            }
                            else
                            {
                                totem.SendMessage("Damage", new HealthEvent(gameObject, damage));
                                totem.DecreaseVida();
                            }
                        }
                    }
                }
            }

            this.collision = collision;
        }