Ejemplo n.º 1
0
    private void FireSlingshot()
    {
        itemHeld.transform.parent = null;
        isHoldingItem             = false;

        itemHeld.GetComponent <Projectile>().InitProjectile();
        itemHeld.GetComponent <Projectile>().Fire(slingshotDirection);
    }
Ejemplo n.º 2
0
 private void HoldItem(ItemPickup itemToHold)
 {
     isHoldingItem = true;
     itemHeld      = itemToHold;
     Destroy(itemHeld.GetComponent <Rigidbody2D>());
     itemToHold.gameObject.transform.parent = this.gameObject.transform;
     itemHeld.GetComponent <Projectile>().DeactivateItemColliders();
 }
Ejemplo n.º 3
0
    void OnTriggerEnter(Collider col)
    {
        ItemPickup item = col.gameObject.GetComponent <ItemPickup>();

        if (item != null)
        {
//            if (!grabbedItems.Contains(item))
//            {
            item.GetComponent <Collider>().enabled = false;
            Destroy(item.GetComponent <Rigidbody>());//.enabled = false;
            grabbedItems.Add(item);
//            }
        }
    }
Ejemplo n.º 4
0
    public void onDie()
    {
        int amount = Random.Range(minItems, maxItems);

        for (int i = 0; i < amount; i++)
        {
            ItemPickup pickup = Instantiate(pickupPrefab.gameObject, transform.position, Quaternion.identity).GetComponent <ItemPickup>();
            pickup.setItem(lootTable[Random.Range(0, lootTable.Count - 1)]);
            pickup.GetComponent <Rigidbody>().AddForce(Random.insideUnitSphere * 100f, ForceMode.Impulse);
        }
    }
Ejemplo n.º 5
0
    void InstantiateItem(InventoryEntry item)
    {
        if (_heldItem != null)
        {
            Transform playerTransform = PlayerManager.instance.playerInstance.transform;
            Transform cameraTransform = PlayerManager.instance.playerCamera.transform;

            ItemPickup newInstance = Instantiate(item.entryItem.resourcePrefab,
                                                 playerTransform.position + cameraTransform.forward * itemDropDistance,
                                                 playerTransform.rotation) as ItemPickup;
            newInstance.GetComponent <Rigidbody>().velocity = cameraTransform.forward * itemDropSpeed;
            newInstance.SetInventoryEntry(item);
        }
    }
Ejemplo n.º 6
0
    private void Spawn(Item item, Vector2 position)
    {
        if (item == null)
        {
            return;
        }

        ItemPickup pickup = Instantiate(pickupPrefab, position, Quaternion.identity);

        pickup.Prime(item);

        if (addRandomForce)
        {
            Vector2 force = (Vector2.up + Vector2.right * Random.Range(-1.0f, 1.0f)).normalized * randomForceMagnitude;
            pickup.GetComponent <Rigidbody2D>().AddForce(force, ForceMode2D.Force);
        }
    }
Ejemplo n.º 7
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            if (pickedUpItem != null && canThrow)
            {
                Debug.Log("Throw Charge");
                if (chargeThrow < 1)
                {
                    chargeThrow += chargeSpeed * Time.deltaTime;
                }
            }
            Debug.DrawLine(camera.transform.position, camera.transform.position + camera.transform.forward * range);
        }

        if (Input.GetMouseButtonDown(0))
        {
            if (pickedUpItem != null)
            {
                Debug.Log("Throw");
                canThrow = true;
            }

            RaycastHit hit;
            if (Physics.Raycast(camera.transform.position, camera.transform.forward, out hit, range) && pickedUpItem == null)
            {
                GameObject obj = hit.collider.gameObject;
                if (obj.GetComponent <ItemPickup>())
                {
                    pickedUpItem = obj.GetComponent <ItemPickup>();
                    canThrow     = false;
                    chargeThrow  = 0;
                }
                else if (obj.GetComponent <Button>())
                {
                    Button btn = obj.GetComponent <Button>();
                    btn.PushDown();
                }
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            if (pickedUpItem != null && canThrow && chargeThrow > 0)
            {
                if (pickedUpItem.GetComponent <Rigidbody>())
                {
                    pickedUpItem.GetComponent <Rigidbody>().AddForce(camera.transform.forward * (minThrowSpeed + chargeThrow * (maxThrowSpeed - minThrowSpeed)), ForceMode.Impulse);
                }
                pickedUpItem = null;
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            pickedUpItem = null;
        }

        if (pickedUpItem != null)
        {
            Vector3 targetPos = camera.transform.position + camera.transform.forward * 1.5f;
            if (pickedUpItem.GetComponent <Rigidbody>())
            {
                Rigidbody rigidbody = pickedUpItem.GetComponent <Rigidbody>();
                rigidbody.velocity     = moveSpeed * Time.deltaTime * Vector3.Distance(pickedUpItem.transform.position, targetPos) * (targetPos - pickedUpItem.transform.position).normalized;
                rigidbody.transform.up = (targetPos - pickedUpItem.transform.position).normalized;
                Debug.DrawRay(pickedUpItem.transform.position, (targetPos - pickedUpItem.transform.position).normalized);
            }
            else
            {
                pickedUpItem.transform.Translate(moveSpeed * Time.deltaTime * (targetPos - pickedUpItem.transform.position).normalized);
            }
        }
    }