So far, I have put up a sign, which is supposed to mark the map as completed, as soon as the player reaches it.
I have also created an empty gameobject called victory and added a Box Collider 2D to it.
I then put it in the same place as the sign.
I have also created a new tag called Victory and added it to the game object as well.
So I guess it’s time for me to write some code, or am I missing anything?
This was I wrote so far:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Victory : MonoBehaviour
{
// Start is called before the first frame update
public void OnTriggerEnter (Collider coll)
{
if (coll.CompareTag("Player"))
{
}
}
// Update is called once per frame
}
It might be working as you expect. Use a Debug.Log("Victory!"); statement inside your block to see if it got there. If so, it’s working and you can add whatever other behavior you want there.
Be sure you are using the correct physics system: this is the 2D forum but I see you using the 3D version of OnTriggerEnter(), so you probably want to start with some basic tutorials.
The conditions necessary are laid out in great detail in the documentation.
What does “register” mean?
Then start with some tutorials. Asking detached random questions in a forum is going to make it infinitely harder to learn what you need.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Victory : MonoBehaviour
{
// Start is called before the first frame update
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Player"))
{
}
}
// Update is called once per frame
}
Is this correct?
To be fair, I have already been watching a lot of tutorials, but I couldn’t find anything regarding this issue.
Yes, that looks fine to me. You should also doublecheck that you have set the “Is Trigger” checkbox on the BoxCollider2D of the Victory object. As mentioned elsewhere in this thread, you can put a Debug.Log() print inside your if statement to get some indication that the code reached the expected point.
Tutorials are not problem solving so I don’t follow what it means to try to find a tutorial on how to solve using the correct callback. Every single tutorial involving 2D physics callbacks would show the correct callback.
Regardless, you seem to have solve your problem by using the correct callback signature which is great.