Home > Enterprise >  Unity OnTriggerEnter2d() Not working | Trying to switch between Scenes
Unity OnTriggerEnter2d() Not working | Trying to switch between Scenes

Time:10-03

I'm pretty new to unity and I've been trying to get this scene switch to work however the trigger doesn't seem to be activating when the player hits it. The debug.Log is doing nothing so I'm stumped. I know my terminology may make no sense so let me show some pictures. If youre able to help it would be extremely helpful. Thank you!

This is the inspector panel for the object I want to trigger

This is the inspector the player

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class SceneChangeScript : MonoBehaviour
{

    public int iLevelToLoad;
    public string sLevelToLoad;

    public bool useIntegerToLoadLevel = false;

    void start()
    {

    }

    void update()
    {

    }



    private void onTriggerEnter2D(Collider2D other)
    {
        if(other.CompareTag("Player"))
        {
        Debug.Log("Somethings Being Triggered!");
        LoadScene();
        }
    }

    void LoadScene()
    {
        if(useIntegerToLoadLevel)
        {
            SceneManager.LoadScene(iLevelToLoad);
        }
        else
        {
            SceneManager.LoadScene(sLevelToLoad);
        }
    }

}

CodePudding user response:

C# convention is methods start with uppercase and C# methods are case-sensitive. Therefore, the following methods need to be corrected to be used by Unity:

  • start => Start
  • update => Update
  • onTriggerEnter2D => OnTriggerEnter2D
  • Related