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.
57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
2 years ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.SceneManagement;
|
||
|
|
||
|
|
||
|
public class TigerInteraction : MonoBehaviour
|
||
|
{
|
||
|
private Camera cam;
|
||
|
[SerializeField]
|
||
|
private float distance = 5f;
|
||
|
[SerializeField]
|
||
|
private LayerMask mask;
|
||
|
private PlayerUI playerUI;
|
||
|
public GameObject tiger;
|
||
|
public GameObject maincam, gamecam;
|
||
|
public bool GameState = true;
|
||
|
// Start is called before the first frame update
|
||
|
void Start()
|
||
|
{
|
||
|
cam = GetComponent<FPSController>().m_fpsCamera;
|
||
|
playerUI= GetComponent<PlayerUI>();
|
||
|
}
|
||
|
|
||
|
// Update is called once per frame
|
||
|
void Update()
|
||
|
{
|
||
|
tiger.SetActive(GameState);
|
||
|
Ray ray = new Ray(cam.transform.position, cam.transform.forward);
|
||
|
|
||
|
playerUI.UpdateText(string.Empty);
|
||
|
|
||
|
Debug.DrawRay(ray.origin, ray.direction * distance);
|
||
|
RaycastHit hitInfo;
|
||
|
if (Physics.Raycast(ray, out hitInfo, distance, mask))
|
||
|
{
|
||
|
if (hitInfo.collider.GetComponent<Interactable>() != null)
|
||
|
{
|
||
|
playerUI.UpdateText(hitInfo.collider.GetComponent<Interactable>().message);
|
||
|
}
|
||
|
|
||
|
if (Input.GetKey(KeyCode.E))
|
||
|
{
|
||
|
if (hitInfo.collider.GetComponent<Interactable>() != null)
|
||
|
{
|
||
|
Cursor.lockState = CursorLockMode.None;
|
||
|
Cursor.visible = true;
|
||
|
hitInfo.collider.GetComponent<Interactable>().BaseInteract();
|
||
|
GameState = false;
|
||
|
maincam.SetActive(false);
|
||
|
gamecam.SetActive(true);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|