Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerRayCast : MonoBehaviour {
- public Canvas FToInteractCanvas;
- public GameObject UIManager;
- public GameObject[] Buttons;
- private RaycastHit hit;
- private bool ObjectInteractibleInRayCast = false;
- private bool UIIsActive = false;
- // Use this for initialization
- void Start () {
- FToInteractCanvas.gameObject.SetActive(false);
- }
- // Update is called once per frame
- void Update () {
- if (Physics.Raycast(transform.position, transform.forward, out hit, 2) && (hit.transform.gameObject.CompareTag("Interactible")) && !ObjectInteractibleInRayCast)
- {
- ObjectInteractibleInRayCast = true;
- }
- if (ObjectInteractibleInRayCast && ((Physics.Raycast(transform.position, transform.forward, out hit, 2) == false) || !(hit.transform.gameObject.CompareTag("Interactible"))))
- {
- ObjectInteractibleInRayCast = false;
- }
- InteractibleUI(ObjectInteractibleInRayCast);
- if (UIManager.GetComponent<GlobalUI>().InMenu == false)
- {
- KeyInteractible(ObjectInteractibleInRayCast);
- }
- }
- public void InteractibleUI(bool inRayCast)
- {
- if ((inRayCast && !UIIsActive) || UIManager.GetComponent<GlobalUI>().InMenu == false)
- {
- UIIsActive = true;
- FToInteractCanvas.gameObject.SetActive(true);
- }
- if ((!inRayCast && UIIsActive) || UIManager.GetComponent<GlobalUI>().InMenu == true)
- {
- UIIsActive = false;
- FToInteractCanvas.gameObject.SetActive(false);
- }
- }
- public void KeyInteractible (bool inRayCast)
- {
- if (Input.GetKeyDown(KeyCode.F) && hit.transform.gameObject == Buttons[0] && inRayCast && UIManager.GetComponent<GlobalUI>().InMenu == false)
- {
- UIManager.GetComponent<PopUpTwoChoiceUICtrl>().VersionPUTC = 1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement