How do you create a victory zone?

How do you create a victory zone that marks the map as completed, as soon as the player reaches it?

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.

9676076--1379192--Screenshot.png

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
}

What else should I put in my script?

A simple approach is to just load a new victory scene / screen and be done.

If you want to stay in the current game for some kind of victory sequence then roughly you would need to:

  • inhibit player control
  • start the victory animation
  • when that animation is done, move onto whatever is next

Yeah, I’m not really there yet.

I just want the game to register that the map has been completed, as soon as the player reaches the sign, like I said.

I also do not want a victory scene, at least not for now.

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.

Imphenzia: How Did I Learn To Make Games:

Um, where should I put it, exactly?

Where can I see if I’m using the 2D version or the 3D version?

Also, how do I change it back to the 2D version again?

What I mean is that I want the game to detect that the map has been completed by the player, I thought that was obvious?

There are simply different function definitions for 2D and 3D collision/trigger interactions:

private void OnTriggerEnter2D(Collider2D collision)

You don’t see it, you know it by first learning how to use it with tutorials etc.

Do you mean like this?

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.

But I will watch some more tutorials.

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.

1 Like

Yeah, sorry I forgot to mention that I have already checked the is trigger checkbox on the victory object.

Anyway, I just put…

Debug.Log("Victory!");

… inside of the if statement, and there’s now a message in the bottom left corner of Unity that says victory when I reach the sign, thanks!

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. :slight_smile:

Regardless, you seem to have solve your problem by using the correct callback signature which is great.