So I tried making a script that when the player presses the “Interact” Input Action it will check if the player is inside a collider of the object “Play”. But for some reason, it doesn’t work. I don’t even get the “Trigger Entered” in the console.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
public class ChangeSceneOnContact : MonoBehaviour
{
public int sceneBuildIndex;
[SerializeField]
private InputActionReference interact;
private void OnEnable()
{
interact.action.performed += PerformInteract;
}
private void OnDisable()
{
interact.action.performed -= PerformInteract;
}
private void PerformInteract(InputAction.CallbackContext obj)
{
void OnTriggerStay2D(Collider2D other)
{
print("Trigger Entered");
if (other.tag == "Player")
{
print("Switching Scene to " + sceneBuildIndex);
SceneManager.LoadScene(sceneBuildIndex, LoadSceneMode.Single);
}
}
}
}