Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerRayCast : MonoBehaviour {
  6.  
  7. public Canvas FToInteractCanvas;
  8. public GameObject UIManager;
  9.  
  10. public GameObject[] Buttons;
  11.  
  12. private RaycastHit hit;
  13. private bool ObjectInteractibleInRayCast = false;
  14.  
  15. private bool UIIsActive = false;
  16.  
  17. // Use this for initialization
  18. void Start () {
  19. FToInteractCanvas.gameObject.SetActive(false);
  20. }
  21.  
  22. // Update is called once per frame
  23. void Update () {
  24. if (Physics.Raycast(transform.position, transform.forward, out hit, 2) && (hit.transform.gameObject.CompareTag("Interactible")) && !ObjectInteractibleInRayCast)
  25. {
  26. ObjectInteractibleInRayCast = true;
  27. }
  28.  
  29. if (ObjectInteractibleInRayCast && ((Physics.Raycast(transform.position, transform.forward, out hit, 2) == false) || !(hit.transform.gameObject.CompareTag("Interactible"))))
  30. {
  31. ObjectInteractibleInRayCast = false;
  32. }
  33.  
  34. InteractibleUI(ObjectInteractibleInRayCast);
  35. if (UIManager.GetComponent<GlobalUI>().InMenu == false)
  36. {
  37. KeyInteractible(ObjectInteractibleInRayCast);
  38. }
  39. }
  40.  
  41. public void InteractibleUI(bool inRayCast)
  42. {
  43. if ((inRayCast && !UIIsActive) || UIManager.GetComponent<GlobalUI>().InMenu == false)
  44. {
  45. UIIsActive = true;
  46. FToInteractCanvas.gameObject.SetActive(true);
  47. }
  48. if ((!inRayCast && UIIsActive) || UIManager.GetComponent<GlobalUI>().InMenu == true)
  49. {
  50. UIIsActive = false;
  51. FToInteractCanvas.gameObject.SetActive(false);
  52. }
  53. }
  54.  
  55. public void KeyInteractible (bool inRayCast)
  56. {
  57. if (Input.GetKeyDown(KeyCode.F) && hit.transform.gameObject == Buttons[0] && inRayCast && UIManager.GetComponent<GlobalUI>().InMenu == false)
  58. {
  59. UIManager.GetComponent<PopUpTwoChoiceUICtrl>().VersionPUTC = 1;
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement