Пример #1
0
    public void removeItem()
    {
        game.GetComponent <SpriteRenderer>().sprite = null;
        item = null;
        game.GetComponent <Effect>().item        = null;
        game.GetComponent <BoxCollider2D>().size = new Vector3(1, 1, 1);

        //updates Item Icon in the UI Widget of the player
        player.GetComponent <PlayerPlatformerController>().updateUI();
    }
Пример #2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.CompareTag("Item") && item == null)
        {
            if (collision.gameObject.GetComponent <ItemScript>().item.GetType() == typeof(Item.HotPotatoItem))
            {
                string temp = name + "Potato";
                game   = GameObject.Find(temp);
                potato = collision.gameObject.GetComponent <ItemScript>().item;
                game.GetComponent <Effect>().item           = potato;
                game.GetComponent <SpriteRenderer>().sprite = collision.gameObject.GetComponent <SpriteRenderer>().sprite;
                potato = (Item.HotPotatoItem)potato;
                time   = Time.time;
                potato.startExplode(game.GetComponent <CircleCollider2D>());
                game.GetComponent <Effect>().center =
                    transform.position;

                Destroy(collision.gameObject);
            }
            else
            {
                string temp = name + "ItemObject";

                game     = GameObject.Find(temp);
                item     = collision.gameObject.GetComponent <ItemScript>().item;
                eff      = game.GetComponent <Effect>();
                eff.item = item;
                game.GetComponent <SpriteRenderer>().sprite = collision.gameObject.GetComponent <SpriteRenderer>().sprite;
                //game.transform.localPosition += (UnityEngine.Vector3)pivot.pivot - game.transform.localPosition;
                game.GetComponent <BoxCollider2D>().size = GameObject.Find(temp)
                                                           .GetComponent <SpriteRenderer>().sprite.bounds.size;

                game.GetComponent <BoxCollider2D>().offset = item.offset;
                eff.center  = transform.position;
                item.player = game;
                item.pickup = this;

                Destroy(collision.gameObject);
                player      = transform.gameObject;
                item.ignore = player;
                //updates Item Icon in the UI Widget of the player
                player.GetComponent <PlayerPlatformerController>().updateUI();
                item.flipped = player.GetComponent <PlayerPlatformerController>().flipped;
            }
        }
    }
Пример #3
0
    private IEnumerator OnTriggerEnter2D(Collider2D other)
    {
        if (item != null)
        {
            if (other.CompareTag("Player"))
            {
                if (item.type == (int)Item.ItemSub.Type.Melee)
                {
                    if (other.gameObject != item.ignore)
                    {
                        Debug.Log(other.gameObject + " " + item.player);
                        if (item.GetType() == typeof(Item.Projectile))
                        {
                            gameObject.GetComponent <SpriteRenderer>().enabled =
                                !gameObject.GetComponent <SpriteRenderer>().enabled;
                        }
                        switch (item.effect)
                        {
                        case (int)Item.ItemSub.Effects.Knockback:
                        {
                            if (item.GetType() == typeof(Item.Projectile))
                            {
                                center = item.main.transform.position;
                            }

                            other.GetComponent <PlayerPlatformerController>().startKnockback(center, item.strength);
                            break;
                        }

                        case (int)Item.ItemSub.Effects.Stun:
                        {
                            other.GetComponent <PlayerPlatformerController>().startStun(item.strength);
                            break;
                        }

                        case (int)Item.ItemSub.Effects.Slow:
                        {
                            if (!ineffect)
                            {
                                ineffect = true;
                                other.GetComponent <PlayerPlatformerController>().maxSpeed /= 2;
                                yield return(new WaitForSeconds(item.strength));

                                other.GetComponent <PlayerPlatformerController>().maxSpeed *= 2;
                                ineffect = false;
                            }

                            break;
                        }
                        }
                    }
                }
                else if (item.GetType() == typeof(Item.HotPotatoItem))
                {
                    potato = (Item.HotPotatoItem)item;

                    GameObject potatoGame = GameObject.Find(other.name + "Potato");
                    ItemPickup itemGame   = other.GetComponent <ItemPickup>();

                    ItemPickup ownPickup = transform.parent.parent.parent.parent.parent.GetComponent <ItemPickup>();
                    GameObject ownPotato = GameObject.Find(ownPickup.name + "Potato");

                    itemGame.potato = item;
                    potatoGame.GetComponent <Effect>().item           = item;
                    potatoGame.GetComponent <SpriteRenderer>().sprite = item.sprite;

                    ownPotato.GetComponent <SpriteRenderer>().sprite = null;
                    potato.unloadPotato(ownPotato.GetComponent <CircleCollider2D>());
                    ownPickup.potato = null;
                    item             = null;

                    itemGame.potato.setStrength((int)(itemGame.potato.strength - (Time.time - ownPickup.time)));
                    itemGame.potato.startExplode(potatoGame.GetComponent <CircleCollider2D>());

                    CircleCollider2D circle = transform.GetComponent <CircleCollider2D>();
                    BoxCollider2D    box    = transform.GetComponent <BoxCollider2D>();

                    if (circle.IsTouching(other))
                    {
                        box.enabled = false;
                        if (!ineffect)
                        {
                            ineffect = true;
                            Vector3 direction = new Vector2(other.bounds.center.x - circle.offset.x,
                                                            other.bounds.center.y - circle.offset.y);

                            direction = direction.normalized * 2;
                            Vector3 end = other.transform.position + direction;
                            while (other.transform.position != end)
                            {
                                other.transform.position =
                                    Vector3.MoveTowards(other.transform.position, end, 10 * Time.deltaTime);
                                yield return(new WaitForEndOfFrame());
                            }

                            ineffect = false;
                        }

                        box.enabled = true;
                    }
                }
            }

            if (item.GetType() == typeof(Item.Projectile))
            {
                if (other.CompareTag("Platform") || other.CompareTag("Item") || other.CompareTag("Player"))
                {
                    Destroy(gameObject);
                }
            }
        }
    }