Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class PickupController : MonoBehaviour {
- private Text pickupText;
- private InventoryInformation inventoryInformation;
- // Fix bug where its not detecting new item when highlighting over it
- private void Start()
- {
- Default();
- }
- private void Default()
- {
- pickupText = InterfaceManager.Instance.MiscellaneousRoot.Find("Pickup").GetComponent<Text>();
- }
- private void Update()
- {
- Camera camera = LocalPlayer.Instance.Character.DefaultCamera;
- Vector3 x = new Vector3(camera.pixelWidth / 2, camera.pixelHeight / 2);
- Ray ray = camera.ScreenPointToRay(x);
- RaycastHit castHit;
- Debug.DrawRay(ray.origin, ray.direction * 10, Color.red, 1);
- if (Physics.Raycast(ray, out castHit, 10))
- {
- if (castHit.transform.tag == "Item")
- {
- if (!pickupText.enabled)
- {
- inventoryInformation = castHit.transform.gameObject.GetComponent<InventoryInformation>();
- pickupText.text = "Press 'E' to pickup " + inventoryInformation.CachedItemName + " [" + inventoryInformation.CachedItemStack.ToString() + "]";
- DisplayText(true);
- }
- }
- else
- {
- inventoryInformation = null;
- DisplayText(false);
- }
- }
- else
- {
- inventoryInformation = null;
- DisplayText(false);
- }
- if (Input.GetKeyDown(KeyCode.E))
- {
- if(inventoryInformation != null)
- {
- Debug.Log("Need to create an item with: " + inventoryInformation.CachedItemName);
- InventorySlot inventorySlot = InventoryManager.Instance.GiveItem(inventoryInformation.CachedItemName, inventoryInformation.CachedItemStack, true);
- //inventorySlot.Default();
- inventorySlot.ItemInformation = inventoryInformation.CachedItemInformation;
- inventorySlot.DisplayInformation();
- Debug.Log(inventorySlot.InventoryID);
- Destroy(inventoryInformation.gameObject);
- DisplayText(false);
- }
- }
- }
- private void DisplayText(bool display)
- {
- pickupText.enabled = display;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement