예제 #1
0
    public void Fire()
    {
        charging = false;
        // Spawn the overworld object and throw it
        PlayerItemSlot itemSlot = GetCurrentItem();

        if (itemSlot == null || itemSlot.empty)
        {
        }
        else
        {
            Item item = itemSlot.item;
            itemSlot.RemoveItems(1);
            GameObject itemProjectile = itemGen.GetOverworldItem(item);
            Vector3    launchPoint    = transform.position;
            Vector2    chrDir         = Character.DirToVector(player.direction);
            launchPoint.x += chrDir.x * 2;
            launchPoint.y += chrDir.y * 2;
            itemProjectile.transform.position = launchPoint;
            Vector2 throwVelocity = chrDir * currentMagnitude;
            itemProjectile.GetComponent <Rigidbody2D>().velocity        = throwVelocity;
            itemProjectile.GetComponent <Rigidbody2D>().angularVelocity = Random.Range(-1 * angularMagnitude, angularMagnitude);
            UIManager.Instance.UpdateSelectedItem(index);
        }

        currentMagnitude = 0;
    }
예제 #2
0
    protected override void Die()
    {
        base.Die();
        OverworldItemGenerator itemGen = GetComponent <OverworldItemGenerator>();

        foreach (Item item in ds.drops)
        {
            if (item != null)
            {
                Debug.Log("item " + item + " is null");
            }
            else
            {
                Debug.Log("item " + item + " is NOT null");
            }
            for (int i = 0; i < Random.Range(1, 4); i++)
            {
                GameObject itemProjectile = itemGen.GetOverworldItem(item);
                itemProjectile.transform.position = transform.position + new Vector3(Random.Range(-0.7f, 0.7f), Random.Range(-0.7f, 0.7f), 0);
            }
        }
    }
예제 #3
0
    protected override void Die()
    {
        base.Die();
        cam.enabled = false;
        OverworldItemGenerator itemGen = GetComponent <OverworldItemGenerator>();

        foreach (PlayerItemSlot itemSlot in ItemManager.Instance.inventory.itemSlots)
        {
            Item item = itemSlot.item;
            for (int i = 0; i < itemSlot.quantity; i++)
            {
                itemSlot.RemoveItems(1);
                GameObject itemProjectile = itemGen.GetOverworldItem(item);
                itemProjectile.transform.position = transform.position;
                Rigidbody2D rb = itemProjectile.GetComponent <Rigidbody2D>();
                rb.AddForce(new Vector3(Random.Range(-0.5f, 0.5f), Random.Range(0.5f, 1f), 0) * 600f);
                rb.freezeRotation = false;
                rb.gravityScale   = 0.5f;
                rb.angularDrag    = 0.5f;
                rb.AddTorque(100f);
            }
        }
    }