Inheritance: MonoBehaviour
Ejemplo n.º 1
0
    void OnTriggerEnter(Collider other)
    {
        PickableItem item = other.GetComponent <PickableItem> ();

        if (item != null)
        {
            switch (item.type)
            {
            case ItemType.AMMO:
                if ((magsCount * magSize) != rounds + remainingRounds)
                {
                    remainingRounds = (magsCount * magSize) - rounds;
                    item.Pickup();
                    MainAudioSource.PlayOneShot(item.soundEffect);
                }
                break;

            case ItemType.HEALTH:
                if (health != maxHealth)
                {
                    MainAudioSource.PlayOneShot(item.soundEffect);
                    health = maxHealth;
                    item.Pickup();
                }
                break;
            }
        }
    }
Ejemplo n.º 2
0
 /// <summary>
 /// Drops the current grabbedItem.
 /// </summary>
 public void dropItem()
 {
     grabbedItem.transform.parent = null;
     grabbedItem.getRigidBody().isKinematic = false;
     grabbedItem = null;
     hasItem     = false;
 }
Ejemplo n.º 3
0
    protected override void ChooseThought()
    {
        bool containsMushroom = false;
        bool containsPotion   = false;

        foreach (GameObject shelfSlot in ShelfSlots)
        {
            PickableItem contained = shelfSlot.GetComponentInChildren <PickableItem>();
            if (contained != null)
            {
                if (contained.GetType() == typeof(Potion))
                {
                    containsPotion = true;
                }

                if (contained.GetType() == typeof(Mushroom))
                {
                    containsMushroom = true;
                }
            }
        }

        if (containsMushroom && containsPotion)
        {
            CurrentThoughtID = 0;
        }
        else if (containsMushroom)
        {
            CurrentThoughtID = 1;
        }
        else if (containsPotion)
        {
            CurrentThoughtID = 2;
        }
    }
Ejemplo n.º 4
0
    private bool PickupClosest()
    {
        PickableItem closest         = null;
        float        closestDistance = float.MaxValue;

        foreach (var hovering in connectedHand.CurrentlyHoveringOver)
        {
            if (hovering.Key == null)
            {
                continue;
            }

            float distance = Vector3.Distance(this.transform.position, hovering.Key.transform.position);
            if (distance < closestDistance)
            {
                closestDistance = distance;
                if (hovering.Key.GetType() == typeof(PickableItem))
                {
                    closest = (PickableItem)hovering.Key;
                }
            }
        }

        if (closest != null)
        {
            connectedHand.EndInteraction(closest);
            AddToInventory(closest);
            inventorySound.Play();
            return(true);
        }
        else
        {
            return(false);
        }
    }
Ejemplo n.º 5
0
    // Update is called once per frame
    protected override void Update()
    {
        if (Input.GetButton("Fire1"))
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit, 100))
            {
                PickableItem     pickable     = hit.collider.GetComponent <PickableItem>();
                InteractibleItem interactible = hit.collider.GetComponent <InteractibleItem>();

                if (pickable != null)
                {
                    RotateTo(pickable.transform.position);
                    MoveTo(target: pickable.transform.position, reach: InteractingDistance, andThen: () => {
                        PickItem(pickable);
                    });
                }
                else if (interactible != null)
                {
                    RotateTo(interactible.transform.position);
                    MoveTo(target: interactible.transform.position, reach: InteractingDistance, andThen: () => {
                        InteractWithItem(interactible);
                    });
                }
                else
                {
                    RotateTo(hit.point);
                    MoveTo(target: hit.point);
                }
            }
        }

        base.Update();
    }
Ejemplo n.º 6
0
    /// <summary>
    /// Picks up the closest item in range.
    /// </summary>
    protected void pickupItem()
    {
        Collider2D[] itemsInRange   = Physics2D.OverlapCircleAll(transform.position, 2f, pickableItems);
        int          nearestItem    = 0;
        float        lowestDistance = 1000f;

        if (itemsInRange.Length > 0)
        {
            int totalItems = itemsInRange.Length;
            for (int i = 0; i < totalItems; i++)
            {
                float distance = Vector2.Distance(transform.position, itemsInRange[i].transform.position);
                if (distance < lowestDistance)
                {
                    lowestDistance = distance;
                    nearestItem    = i;
                }
            }
            grabbedItem = itemsInRange[nearestItem].GetComponent <PickableItem>();
            if (!grabbedItem.getIsUsed() && !grabbedItem.getIsPicked())
            {
                hasItem = true;
                grabbedItem.setIsUsed(false);
                grabbedItem.setIsPicked(true);
                grabbedItem.pickUp(pickUpSpot);
            }
        }
    }
Ejemplo n.º 7
0
    /// <summary>
    /// Make some items pickable
    /// </summary>
    /// <returns>return list of pickalbe items</returns>
    private List <SceneItem> MakeSomeSceneItemsPickable(List <SceneItem> visibleItemList, BuildParams buildParams)
    {
        List <SceneItem> pickableItemList = new List <SceneItem>();

        int maxPickableItemCount = Math.Min(buildParams.PickableItemCount, visibleItemList.Count);

        for (int i = 0; i < maxPickableItemCount; i++)
        {
            SceneItem item = visibleItemList[i];

            var spriteRenderer = item.gameObject.GetComponent <SpriteRenderer>();
            if (spriteRenderer != null)
            {
                var boxCollider = item.gameObject.GetComponent <BoxCollider2D>();
                if (boxCollider == null)
                {
                    var size = spriteRenderer.sprite.bounds.size;

                    boxCollider      = item.gameObject.AddComponent <BoxCollider2D>();
                    boxCollider.size = new Vector2(size.x, size.y);
                }
            }

            PickableItem component = item.gameObject.AddComponent <PickableItem>();
            component.Controller = buildParams.Controller;
            pickableItemList.Add(item);
        }
        return(pickableItemList);
    }
Ejemplo n.º 8
0
    public PickableItem ReleaseItem()
    {
        var item = this._item;

        this._item = null;
        return(item);
    }
Ejemplo n.º 9
0
 private void SpawnObjectInHand(NVRHand hand)
 {
     if (hand.Inputs[NVRButtons.Grip].PressDown)
     {
         if (inevtoryController.RemovefromInventory(typeToRemove))
         {
             Debug.Log("Successfully removed item");
             //Spawn an object and make the hand interact with it
             GameObject       spawnedObject = (GameObject)Instantiate(prefabToSpawn, transform.position, transform.rotation);
             ExplosionEnabler rocket        = prefabToSpawn.GetComponent <ExplosionEnabler>();
             if (rocket)
             {
                 rocket.playerHealth = leftHand.GetComponent <HealthBarController>();
             }
             Medicine med = prefabToSpawn.GetComponent <Medicine>();
             if (med)
             {
                 Debug.Log("Spawned Medicine in hand");
                 med.health = leftHand.GetComponent <HealthBarController>();
                 med.head   = GameObject.Find("Head").GetComponent <NVRHead>();
             }
             PickableItem item = spawnedObject.GetComponent <PickableItem>();
             if (item != null)
             {
                 hand.BeginInteraction(item);
                 //TODO: Remove velocity
                 item.gameObject.GetComponent <Rigidbody>().velocity = new Vector3(0.0f, 0.0f, 0.0f);
             }
             else
             {
                 hand.BeginInteraction(spawnedObject.GetComponent <NVRExampleGun>());
             }
         }
     }
 }
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Item") // entra en contacto con un iterm y se activa la capacidad de interactuar con este
        {
            PickableItem pim = other.GetComponent <PickableItem>();
            currentItem = pim;

            canInteract = true;
        }
        else if (other.tag == "RoomDetector")
        {
            if (other.gameObject.GetComponent <PickableItem>() != null)
            {
                //La puerta tiene un candado
                currentItem = other.GetComponent <PickableItem>();
                canInteract = true;
            }
            else if (other.GetComponent <RoomDetectorContoller>() != null)
            {
                currentRoomDetector = other.GetComponent <RoomDetectorContoller>();
                canGoDoor           = true;
            }
            else if (other.GetComponent <DoorwayLockController>() != null)
            {
                doorwayLockDetector = other.GetComponent <DoorwayLockController>();
                canInteract         = true;
            }
        }
    }
Ejemplo n.º 11
0
    public void TryInsertItem(PickableItem item)
    {
        bool found = false;

        foreach (var interaction in interactions)
        {
            if (interaction.ItemID == item.ID && interaction.Active)
            {
                interaction.OnActivated();
                found = true;
                break;
            }
        }
        if (found)
        {
            foreach (var interaction in interactions)
            {
                if (interaction.Active)
                {
                    return;
                }
            }
            enabled = false;
        }
        else
        {
            Door door = GetComponent <Door>();
            if (door != null)
            {
                door.PlayAudio("wrong_item");
            }
        }
    }
Ejemplo n.º 12
0
    public void UpdateHand(GameObject itemInHand)
    {
        PickableItem pickableItem       = itemInHand.GetComponent <PickableItem>();
        Sprite       itemToInventoryPic = pickableItem.itemInventorySprite;
        Image        handImage          = hand.GetComponent <Image>();

        handImage.sprite = itemToInventoryPic;
    }
Ejemplo n.º 13
0
 public bool GrabItem(PickableItem item)
 {
     if (this._item != null)
     {
         return(false);
     }
     this._item = item;
     return(true);
 }
Ejemplo n.º 14
0
 private void Drop()
 {
     if (_pickedUpItem == null)
     {
         return;
     }
     _pickedUpItem.Drop();
     _pickedUpItem = null;
 }
Ejemplo n.º 15
0
    private void Update()
    {
        if (consumesItem)
        {
            ConsumableItem consumableItem = itemOnSurface as ConsumableItem;
            if (amountOnSurface == numberNeeded && itemOnSurface == null)
            {
                amountOnSurface = 0;
                PlaceItemOnMe(Instantiate(itemToSpawn, positionOfItem.position, positionOfItem.rotation, transform));
            }
            else if (consumableItem && consumableItem.canBeUsedFor == typeToConsume)
            {
                if (placeDownSound.Length != 0)
                {
                    consumeItemSoundEvent = FMODUnity.RuntimeManager.CreateInstance(consumeItemSound);
                    consumeItemSoundEvent.start();
                }

                Debug.Log("Consume item");
                Destroy(itemOnSurface.gameObject);
                itemOnSurface = null;
                amountOnSurface++;
            }

            textForConsumeables.text = amountOnSurface + "/" + numberNeeded;
        }

        if (itemOnSurface is UsableItem)
        {
            UsableItem item = itemOnSurface as UsableItem;

            if (item.percentageFull != 100 && hasItemOnCoroutine == null)
            {
                hasItemOnCoroutine = StartCoroutine(HasItemOnRoutine(item));

                if (placeDownSound.Length != 0)
                {
                    soundEvent = FMODUnity.RuntimeManager.CreateInstance(placeDownSound);
                    soundEvent.start();
                    Debug.Log("Playing put down sound");
                }
            }
            else if (item.percentageFull == 100 && hasItemOnCoroutine != null)
            {
                StopCoroutine(hasItemOnCoroutine);
                hasItemOnCoroutine = null;
                soundEvent.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
            }
        }
        else if (hasItemOnCoroutine != null)
        {
            StopCoroutine(hasItemOnCoroutine);
            hasItemOnCoroutine = null;
            soundEvent.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
        }
    }
Ejemplo n.º 16
0
    [SerializeField] private Transform handTransform;     //Should also be a child of the player gameobject. This needs to be animated for the keyframes that move the hand

    void Update()
    {
        if (carryingItem && Input.GetMouseButtonDown(1))
        {
            pickedUpItem.transform.SetParent(null);
            pickedUpItem.transform.position = spawnPosition.position;
            pickedUpItem.GetComponent <Rigidbody2D>().AddForce(transform.right * throwingForce.x + transform.up * throwingForce.y);
            pickedUpItem = null;
        }
    }
Ejemplo n.º 17
0
    /**
     * Throws the item to the ground
     */
    private void throwItem()
    {
        // Debug.Log ("throw item");

        currentItem.activatePhysics();

        currentItem.rigidbody.AddForce(gameObject.transform.forward * throwForce, ForceMode.Impulse);

        currentItem = null;
    }
Ejemplo n.º 18
0
    public void ItemPicked(PickableItem item)
    {
        ++pickedItemCount;

        if (PickableItems.Length == pickedItemCount)
        {
            Winner          = SkopjeWinner.Human;
            SkopjeGameState = SkopjeGameState.Over;
        }
    }
Ejemplo n.º 19
0
    private void Push(PickableItem item)
    {
        Vector2 dir = (item.transform.position - transform.position).normalized * force;

        object[] rpcParams = new object[2] {
            (object)networkObject.NetworkId, (object)dir
        };

        item.networkObject.SendRpc(PickableItem.RPC_PUSH, Receivers.Owner, rpcParams);
    }
Ejemplo n.º 20
0
    /// <summary>
    /// Agrega un item a la lista de items que tiene el jugador
    /// </summary>
    /// <param name="newItem"> el nuevo item recogido </param>
    public void AddItem(PickableItem newItem)
    {
        PickableItemInfo i = newItem.piInfo;

        inventory.Add(i);

        Destroy(newItem.gameObject);

        uiManagerReference.addItem(newItem.spriteItem);
    }
Ejemplo n.º 21
0
    void managePickUp(Collider col)
    {
        PickableItem item = col.GetComponent <PickableItem>();

        if (null != item)
        {
            Logger.Log("Hero::managePickUp collided with DNA! bit=" + item.getDNABit(), Logger.Level.INFO);
            item.pickUp();
            RedMetricsManager.get().sendEvent(TrackingEvent.PICKUP, new CustomData(CustomDataTag.DNABIT, item.getDNABit().getInternalName()));
        }
    }
Ejemplo n.º 22
0
 private void OnTriggerExit(Collider other)
 {
     if (other.tag == "Pickable")
     {
         PickableItem pickable = other.GetComponent <PickableItem>();
         if (pickable != null && other.gameObject.activeSelf)
         {
             closeItems.Remove(pickable);
         }
     }
 }
Ejemplo n.º 23
0
    private void OnCollisionEnter2D(Collision2D other)
    {
        var pickable = other.transform.GetComponent <PickableItem>();

        if (pickable && pickedUpItem == null)     //This kind of depends on the game design because maybe you want to pick it up if you're carrying something already
        {
            pickedUpItem = pickable;
            pickable.transform.SetParent(handTransform);
        }

        pickable.transform.localPosition.Set(0, 0, 0);
    }
Ejemplo n.º 24
0
    /// <summary>
    /// Throws the grabbed item.
    /// </summary>
    /// <param name="dir">direction of throw</param>
    protected virtual void throwItem()
    {
        if (grabbedItem != null)
        {
            grabbedItem.transform.parent = null;
            grabbedItem.getRigidBody().isKinematic = false;
            grabbedItem.setIsPicked(false);
            grabbedItem.setIsUsed(true);
            grabbedItem.GetComponent <ThrowableItem>().onThrow();

            float throwForce;
            if (chargeAmount > 0)
            {
                throwForce   = grabbedItem.getVelocity() + (chargeAmount * maxThrowForce / 2);
                chargeAmount = 0;
            }
            else
            {
                throwForce = grabbedItem.getVelocity();
            }

            switch (throwDirection)
            {
            case Utilities.direction.Up: grabbedItem.getRigidBody().AddForce(new Vector2(0, throwForce), ForceMode2D.Impulse); break;

            case Utilities.direction.Down: grabbedItem.getRigidBody().AddForce(new Vector2(0, -throwForce), ForceMode2D.Impulse); break;

            case Utilities.direction.Left: grabbedItem.getRigidBody().AddForce(new Vector2(-throwForce, 0), ForceMode2D.Impulse); break;

            case Utilities.direction.Right: grabbedItem.getRigidBody().AddForce(new Vector2(throwForce, 0), ForceMode2D.Impulse); break;

            case Utilities.direction.UpLeft: grabbedItem.getRigidBody().AddForce(new Vector2(-throwForce, throwForce), ForceMode2D.Impulse); break;

            case Utilities.direction.UpRight: grabbedItem.getRigidBody().AddForce(new Vector2(throwForce, throwForce), ForceMode2D.Impulse); break;

            case Utilities.direction.DownLeft: grabbedItem.getRigidBody().AddForce(new Vector2(-throwForce, -throwForce), ForceMode2D.Impulse); break;

            case Utilities.direction.DownRight: grabbedItem.getRigidBody().AddForce(new Vector2(throwForce, -throwForce), ForceMode2D.Impulse); break;
            }
            grabbedItem.GetComponent <ThrowableItem>().setDirection(throwDirection);
            grabbedItem = null;
            hasItem     = false;
        }
        if (isGrounded)
        {
            state = Utilities.state.Idle;
        }
        else
        {
            state = Utilities.state.Air;
        }
    }
Ejemplo n.º 25
0
    private Vector3 GetPosOnPickedPlane(PickableItem item)
    {
        Ray ray = _camera.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out RaycastHit hit, float.MaxValue, LayerMask.GetMask("PickedItemsDragPlane")))
        {
            float xOffset = item.collider.transform.position.x - item.transform.position.x;
            float zOffset = item.collider.transform.position.z - item.transform.position.z;
            return(hit.point - Vector3.right * xOffset - Vector3.forward * zOffset);
        }

        return(Vector3.zero);
    }
Ejemplo n.º 26
0
    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject != null)
        {
            PickableItem item = collision.gameObject.GetComponent <PickableItem> ();

            if (item != null)
            {
                player.itemBurned(item);

                item.burn(transform.position);
            }
        }
    }
Ejemplo n.º 27
0
    // ------------------------------------------------------------------------
    private void OnCollisionEnter2D(Collision2D other)
    {
        if (!networkObject.IsOwner)
        {
            return;
        }

        PickableItem item = other.transform.GetComponent <PickableItem>();

        if (item != null)
        {
            Push(item);
        }
    }
Ejemplo n.º 28
0
    void OnTriggerEnter(Collider other)
    {
        PickableItem item = other.GetComponent <PickableItem>();

        if (item)
        {
            if (item.objectType == InventoryObjectType.Injection)
            {
                health.DecreaseHealth(injectionDamage);
                hitSound.Play();
                Debug.Log("Decreased Zombies Health by " + injectionDamage);
            }
        }
    }
Ejemplo n.º 29
0
    //Method to drop item
    private void DropItem(PickableItem item)
    {
        //Remove reference
        pickedItem = null;

        //Remove Parent
        item.transform.SetParent(null);

        //Re-enable rigidbody
        item.Rb.isKinematic = false;

        //Throw item forward slightly
        item.Rb.AddForce(item.transform.forward * 2, ForceMode.VelocityChange);
    }
Ejemplo n.º 30
0
	// Use this for initialization
	void Start () {

		curCarryingAmmo = maxCarryingAmmo;
		currAmmo = MaxClipAmmo;

		rigidBody = GetComponent<Rigidbody> ();
		rigidBody.isKinematic = true;
		boxCol = GetComponent<BoxCollider> ();
		pickableItem = GetComponentInChildren<PickableItem> ();

		audioSource = GetComponent<AudioSource> ();
		weaponAnim = GetComponent<Animator> ();
		scale = transform.localScale;
	}
Ejemplo n.º 31
0
    void OnTriggerEnter(Collider other)
    {
        PickableItem item = other.GetComponent <PickableItem>();

        if (item)
        {
            if (item.objectType == InventoryObjectType.Knife)
            {
                health.DecreaseHealth(knifeDamage);
                hitSound.Play();
                Debug.Log("Decreased Robots Health by " + knifeDamage);
            }
        }
    }
Ejemplo n.º 32
0
    // Use this for initialization
    void Start()
    {
        /*bulletSpawnGO = Instantiate(bulletPrefab, transform.position, Quaternion.identity) as GameObject;
        bulletSpawnGO.AddComponent<ParticleDirection>();
        bulletSpawnGO.GetComponent<ParticleDirection>().weapon = bulletSpawn;
        bulletPart = bulletSpawnGO.GetComponent<ParticleSystem>();*/

        curCarryingAmmo = maxCarryingAmmo;
        curAmmo = MaxClipAmmo;
        pickableItem = GetComponentInChildren<PickableItem>();
        curAmmo = MaxClipAmmo;
        rigidBody = GetComponent<Rigidbody>();
        rigidBody.isKinematic = true;
        boxCol = GetComponent<BoxCollider>();

        audioSource = GetComponent<AudioSource>();
        scale = transform.localScale;
        weaponAnim = GetComponent<Animator>();
    }
Ejemplo n.º 33
0
 void handleItem(PickableItem item)
 {
     if(player.ActiveAbilities.onItemPickup != null)
         player.ActiveAbilities.onItemPickup (item);
     if (item.GetComponent<Weapon>())
     {
         if (player.CurrentWeapon)
             player.CurrentWeapon.destroy();
         player.useWeapon(item.GetComponent<Weapon>());
     }
     else if(item.GetComponent<Bonus>())
     {
         if (item.GetComponent<Bonus>().Duration != 0)
             player.GetComponent<BonusManager>().handleBonus(item.GetComponent<Bonus>());
         else
             item.GetComponent<Bonus>().activate();
     }
     else
         Debug.LogError("ItemsPickup : Unrecognized PickableItem!");
 }
Ejemplo n.º 34
0
 public override void onItemPickup(PickableItem item)
 {
     if(item is HealthBonus)
         ((HealthBonus)item).HealthRecovered += ((HealthBonus)item).HealthRecovered * increasedHealPercentage / 100;
 }
Ejemplo n.º 35
0
 public virtual void onItemPickup(PickableItem item)
 {
 }