예제 #1
0
 /// <summary>
 /// drop catchable
 /// </summary>
 /// <param name="item">catchable to drop</param>
 public void Drop(Catchable item)
 {
     if (item == null)
     {
         return;
     }
     item.transform.parent = GameManager.AssetsManager.InteractiveTransform;
     item.GetComponent <Collider2D>().enabled = true;
 }
예제 #2
0
    private void ThrowCurrentStickman()
    {
        Vector2 velocity = ((Vector2)Input.mousePosition - prevmousePos) * 20;

        if (GameCamera.NeedFlip)
        {
            velocity.Set(-velocity.x, velocity.y);
        }
        Debug.Log(velocity);
        current.Throw(velocity);
        current = null;
    }
예제 #3
0
 /// <summary>
 /// Add catchable to the inventory
 /// </summary>
 /// <param name="item">catchable to add</param>
 public void Add(Catchable item)
 {
     if (item == null)
     {
         return;
     }
     item.transform.parent                    = InventoryTransform;
     item.transform.localPosition             = new Vector3();
     item.GetComponent <Collider2D>().enabled = false;
     AddConsumable(item as Consumable);
     AddPassive(item as Passive);
     AddEquipment(item as Equipment);
 }
예제 #4
0
    private void TryToCatchStickman()
    {
        RaycastHit2D hit = Physics2D.Raycast(cam.ScreenToWorldPoint(Input.mousePosition), Vector3.forward, 1, mask);

        if (hit)
        {
            Catchable fly = hit.transform.GetComponent <Catchable>();
            if ((fly != null) & (!fly.IsFlying))
            {
                fly.Catch();
                current      = fly;
                prevmousePos = Input.mousePosition;
            }
        }
    }
예제 #5
0
        private void Catch(Catchable catchable)
        {
            var newPosition       = new Vector3();
            var catchableCollider = catchable.GetComponent <BoxCollider>();

            if (catchableCollider != null)
            {
                newPosition.y = catchableCollider.size.y / 2;
                newPosition.z = catchableCollider.size.z / 2;
            }

            _takenObject = catchable.GetComponent <Catchable>().Catch(
                ObjectPosition,
                newPosition,
                new Quaternion());
        }
예제 #6
0
    // Asigna un objeto al contenedor
    public void SetItem(GameObject newItem)
    {
        if (newItem == gameObject)
        {
            return;
        }
        if (!Empty())
        {
            throw new UnityException("El contenedor no estaba vacío");
        }
        Catchable obj = newItem.GetComponent <Catchable>();

        obj.Done();
        Done();
        obj.GetContainer()?.RemoveItem();
        obj.SetContainer(this);
        item = newItem;
        item.transform.parent = gameObject.transform;
        realItemPosition      = new Vector3(itemPosition.x,
                                            itemPosition.y + item.GetComponentInChildren <Renderer>().bounds.size.y / 2,
                                            itemPosition.z);
    }
예제 #7
0
 private void InitCatching()
 {
     catchScript = GetComponent <Catchable>();
     catchScript.OnCatchEvent += SetFly;
     catchScript.OnThrowEvent += () => GetComponent <Collider2D>().enabled = true;
 }