I’m trying to make it so when the player walks up to a door, the scene changes. I have a simple script to do this using raycasting, which for some reason isn’t working. I’m not seeing a problem, but if anyone sees something that I can’t see, please let me know.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ExitApartments : MonoBehaviour
{
public GameObject interactText;
public LayerMask doorMask;
void Start()
{
interactText.SetActive(false);
}
void Update()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, 3, doorMask))
{
interactText.SetActive(true);
if (Input.GetKeyDown(KeyCode.E))
{
SceneManager.LoadScene(sceneName: "Street");
}
}
if (!Physics.Raycast(ray, 3, doorMask))
{
interactText.SetActive(false);
}
}
}
'''