using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class DoorInteraction : MonoBehaviour { private Camera cam; [SerializeField] private float distance=5f; [SerializeField] private LayerMask mask; public GameObject door; public GameObject maincam,gamecam; public bool GameState=true; // Start is called before the first frame update void Start() { cam=GetComponent().m_fpsCamera; } // Update is called once per frame void Update() { door.SetActive(GameState); Ray ray = new Ray(cam.transform.position, cam.transform.forward); Debug.DrawRay(ray.origin, ray.direction * distance); RaycastHit hitInfo; if(Physics.Raycast(ray, out hitInfo, distance, mask)) { if(Input.GetKey(KeyCode.E)) { if(hitInfo.collider.GetComponent()!=null) { // change camera // Debug.Log(hitInfo.collider.GetComponent().message); Cursor.lockState = CursorLockMode.None; Cursor.visible = true; hitInfo.collider.GetComponent().BaseInteract(); GameState=false; maincam.SetActive(false); gamecam.SetActive(true); } } } } }