void HandleHealthPotionUse(InventoryItemStack stack) { if (health < 100) { health = Math.Min(health + 25, 100); VRInventory.RemoveItem("Health Potion", 1, stack); UpdateBars(); } else { ShowMessage("You are already at full health!"); } }
public void OpenDoor() { if (open) { return; } // ignore attempts to open the door from to far away var distance = Vector3.Distance(this.transform.position, Camera.main.transform.position); if (distance > 3f) { return; } // This checks to see if the player is holding the key // alternatively, we could have just used 'vrInventory.HasItem("Key")' if we just want to see that they have it if (vrInventory.GetEquippedItemName() == "Key") { open = true; // open the door myAnim.SetTrigger("OpenDoor"); // put the key away vrInventory.UnEquipItem(); // Get rid of the key, we don't need it anymore vrInventory.RemoveItem("Key"); if (doorOpenSound != null) { AudioSource.PlayClipAtPoint(doorOpenSound, this.transform.position); } } else { // show message if (vrInventory.HasItem("Key")) { exampleController.ShowMessage("Equip the key to open this door."); } else { exampleController.ShowMessage("A key is required to open this door."); } } }
public void OnItemSelected(InventoryItemStack stack) { Debug.Log(stack.item.name); VRInventory.RemoveItem("Balde", 1, stack); //UpdateBars(); }
public override void OnInspectorGUI() { SO_target.Update(); bool forceItemReRender = false; EditorGUI.BeginChangeCheck(); itemDatabase.objectReferenceValue = EditorGUILayout.ObjectField("Item Database", itemDatabase.objectReferenceValue, typeof(InventoryItemDatabase), false); if (itemDatabase.objectReferenceValue == null) { EditorGUILayout.HelpBox("Please select an Inventory Item Database", MessageType.Warning); vrInventoryTarget.items.Clear(); return; } EditorGUILayout.PropertyField(inventoryTriggerMode); if (inventoryTriggerMode.enumValueIndex == (int)VRInventory.eInventoryTriggerMode.InputFire1) { EditorGUILayout.PropertyField(hideWhenItemSelected); } EditorGUI.BeginChangeCheck(); { EditorGUILayout.PropertyField(showInventoryItemsInEditMode); } if (EditorGUI.EndChangeCheck()) { forceItemReRender = true; } EditorGUILayout.Space(); EditorGUILayout.LabelField("Save / Load", EditorStyles.boldLabel); EditorGUILayout.PropertyField(autoSave); if (autoSave.boolValue) { EditorGUILayout.PropertyField(saveSlotName); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel(" "); if (GUILayout.Button("Clear Save")) { PlayerPrefs.SetString("vrInventory_" + saveSlotName.stringValue, ""); PlayerPrefs.Save(); EditorUtility.DisplayDialog("Success", "Save slot '" + saveSlotName.stringValue + "' cleared.", "Okay"); } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.Space(); var changedItems = RenderItemListEditor(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Events", EditorStyles.boldLabel); EditorGUILayout.PropertyField(onItemSelected); EditorGUILayout.PropertyField(onItemPickedUp); EditorGUILayout.Space(); showReferences = EditorGUI.Foldout(EditorGUILayout.GetControlRect(), showReferences, "UI References", true); if (showReferences) { EditorGUILayout.PropertyField(inventoryUIPrefab); EditorGUILayout.PropertyField(itemTemplate); EditorGUILayout.PropertyField(inventoryPositionTransform); EditorGUILayout.PropertyField(handPosition); } if (EditorGUI.EndChangeCheck()) { SO_target.ApplyModifiedProperties(); if (!Application.isPlaying) { UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(vrInventoryTarget.gameObject.scene); } } if (forceItemReRender) { vrInventoryTarget.ItemsUpdated(); } foreach (var addedItemName in changedItems["added"]) { vrInventoryTarget.AddItem(addedItemName, newItemQuantity); } foreach (var removedItemName in changedItems["removed"]) { vrInventoryTarget.RemoveItem(removedItemName, -1); } }