I tried so many ways and they didn’t work too well. I’m new at coding and im trying to use a device to change scene and i want to show a text on the canvas when i look to the object (using raycast).
Pls help ![]()
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class SelectionManager : MonoBehaviour
{
[SerializeField] private string selectableTag = "minigameDevice";
public Text InteractableText;
public void Update ()
{
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 5))
var selection = hit.transform;
if (selection.CompareTag(selectableTag))
{
InteractableText.gameObject.SetActive(true);
}
if (Physics.Raycast(ray, out hit, 5) && (Input.GetKey(KeyCode.E)))
{
var selection = hit.transform;
if (selection.CompareTag(selectableTag))
{
SceneManager.LoadScene(0);
}
}
}
}