Esempio n. 1
0
    /****************************************** PRIVATE METHODS ******************************************/

    void Grab()
    {
        if (!isHoldingItem)
        {
            Vector2      grabBox      = new Vector2(grabRadius, GetHeight());
            Collider2D[] gnomesToGrab = Physics2D.OverlapBoxAll(grabCenter.position, grabBox, 0f, whatCanBeGrabbed);

            foreach (Collider2D coll in gnomesToGrab)
            {
                coll.gameObject.transform.parent = gameObject.transform;

                GnomeController gnome = coll.gameObject.GetComponent <GnomeController> ();
                ClockController clock = coll.gameObject.GetComponent <ClockController> ();

                if (gnome != null)
                {
                    Vector3 newGnomePosition = gnomeHolster.position;
                    newGnomePosition.y += gnome.GetWidth();
                    coll.gameObject.transform.position = newGnomePosition;
                    gnome.Flip(90);
                    gnome.Freeze();

                    // Fix the scale
                    Vector3 gnomeScale = new Vector3(1.1f, 1.1f, 0.3f);
                    coll.gameObject.transform.localScale = gnomeScale;

                    currentGnome = coll.gameObject;
                    animator.SetBool("isCarrying", true);
                    this.isHoldingItem = true;
                }
                else if (clock != null)
                {
                    Vector3 newClockPosition = gnomeHolster.position;
                    newClockPosition.y += clock.GetHeight() / 4;
                    coll.gameObject.transform.position = newClockPosition;
                    clock.FixRotation();
                    clock.Freeze();

                    // Fix the scale
                    Vector3 clockScale = new Vector3(0.26f, 0.26f, 0.26f);
                    coll.gameObject.transform.localScale = clockScale;

                    animator.SetBool("isCarrying", true);
                    this.isHoldingItem = true;
                    currentClock       = coll.gameObject;
                    string name = currentClock.GetComponent <ClockController> ().GetName();
                    EventManagerController.FireClockSelectedEvent(name);
                }
            }
        }
    }