Код: Выделить всё
using UnityEngine;
using TMPro;
using System.Collections;
using System.Collections.Generic;
public class Doors : MonoBehaviour
{
public GameObject OpenPrompt;
public LayerMask interactableLayer;
public float raycastDistance = 100f;
private bool ableToOpen;
public GameObject Player;
public Transform LevelStart;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
ableToOpen = false;
OpenPrompt.SetActive(false);
}
// Update is called once per frame
void Update()
{
Ray ray = new Ray(transform.position, transform.forward);
if(Physics.Raycast(ray, out RaycastHit hit, raycastDistance, interactableLayer) && hit.collider.CompareTag("Door"))
{
OpenPrompt.SetActive(true);
ableToOpen = true;
}
else
{
OpenPrompt.SetActive(false);
ableToOpen = false;
}
if(Input.GetKeyDown("e") && ableToOpen == true)
{
Player.transform.position = LevelStart.position;
Debug.Log("Traversing Through Door");
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... s-position