Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class PickupController : MonoBehaviour {
  7.  
  8. private Text pickupText;
  9.  
  10. private InventoryInformation inventoryInformation;
  11.  
  12. // Fix bug where its not detecting new item when highlighting over it
  13.  
  14. private void Start()
  15. {
  16. Default();
  17. }
  18.  
  19. private void Default()
  20. {
  21. pickupText = InterfaceManager.Instance.MiscellaneousRoot.Find("Pickup").GetComponent<Text>();
  22. }
  23.  
  24. private void Update()
  25. {
  26.  
  27.  
  28. Camera camera = LocalPlayer.Instance.Character.DefaultCamera;
  29. Vector3 x = new Vector3(camera.pixelWidth / 2, camera.pixelHeight / 2);
  30.  
  31. Ray ray = camera.ScreenPointToRay(x);
  32. RaycastHit castHit;
  33.  
  34. Debug.DrawRay(ray.origin, ray.direction * 10, Color.red, 1);
  35. if (Physics.Raycast(ray, out castHit, 10))
  36. {
  37. if (castHit.transform.tag == "Item")
  38. {
  39. if (!pickupText.enabled)
  40. {
  41. inventoryInformation = castHit.transform.gameObject.GetComponent<InventoryInformation>();
  42.  
  43. pickupText.text = "Press 'E' to pickup " + inventoryInformation.CachedItemName + " [" + inventoryInformation.CachedItemStack.ToString() + "]";
  44. DisplayText(true);
  45. }
  46.  
  47. }
  48. else
  49. {
  50. inventoryInformation = null;
  51. DisplayText(false);
  52. }
  53. }
  54. else
  55. {
  56.  
  57. inventoryInformation = null;
  58. DisplayText(false);
  59. }
  60.  
  61.  
  62. if (Input.GetKeyDown(KeyCode.E))
  63. {
  64. if(inventoryInformation != null)
  65. {
  66. Debug.Log("Need to create an item with: " + inventoryInformation.CachedItemName);
  67.  
  68. InventorySlot inventorySlot = InventoryManager.Instance.GiveItem(inventoryInformation.CachedItemName, inventoryInformation.CachedItemStack, true);
  69. //inventorySlot.Default();
  70. inventorySlot.ItemInformation = inventoryInformation.CachedItemInformation;
  71. inventorySlot.DisplayInformation();
  72. Debug.Log(inventorySlot.InventoryID);
  73.  
  74. Destroy(inventoryInformation.gameObject);
  75.  
  76. DisplayText(false);
  77. }
  78. }
  79. }
  80.  
  81. private void DisplayText(bool display)
  82. {
  83. pickupText.enabled = display;
  84. }
  85.  
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement