You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
2 years ago
|
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<FPSController>().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<Interactable>()!=null)
|
||
|
{
|
||
|
// change camera
|
||
|
// Debug.Log(hitInfo.collider.GetComponent<Interactable>().message);
|
||
|
Cursor.lockState = CursorLockMode.None;
|
||
|
Cursor.visible = true;
|
||
|
hitInfo.collider.GetComponent<Interactable>().BaseInteract();
|
||
|
GameState=false;
|
||
|
maincam.SetActive(false);
|
||
|
gamecam.SetActive(true);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|