Advertisement
Guest User

Item script

a guest
Jun 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class itemScript : MonoBehaviour {
  7.  
  8. public GameObject inventorySlot;
  9. public GameObject player;
  10. public laikaController controller;
  11. [SerializeField] private Text interactingText;
  12. public bool thereIsAnItem = false;
  13. public bool isActive = false;
  14.  
  15. void Update() {
  16.  
  17. Vector3 distance = transform.position - player.transform.position;
  18.  
  19.  
  20. if (thereIsAnItem) {
  21. inventorySlot.SetActive(true);
  22. }
  23. if (controller.canInteract == false) {
  24. interactingText.text = ("");
  25. }
  26.  
  27. if (controller.canInteract == true) {
  28. if (isActive == false) {
  29. interactingText.text = ("Press E to pick up this item.");
  30. if (Input.GetKeyDown(KeyCode.E)) {
  31. inventorySlot.SetActive(true);
  32. thereIsAnItem = true;
  33. controller.canInteract = false;
  34. interactingText.text = ("");
  35. isActive = true;
  36. }
  37. } else if (isActive == true) {
  38. interactingText.text = ("You already own this item.");
  39. }
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement