how do I tell the game my scene is complete

Hello. I’m hoping to get pointed in the right direction. I’m working on a children’s educational app. In each scene I have multiple sprites that can be dragged to their respective trigger locations. When the object is dropped in it’s proper trigger it locks into place and can no longer be dragged. A scene might have anywhere between 3 and 8 of these objects/triggers. When the last trigger is satisfied (they can be dropped in any order, doesn’t have a sequential component to it) I need the game to recognize this, scale up the main object in the scene, play some audio, then load the next scene. How do I track the triggers that need to be satisfied? How do I know when all of them have been completed?

I’m not even sure how to search for what I want to learn here. Am I using variables to track each successful trigger? A list? I’m a complete noob when it comes to coding, and have gotten this far by searching the forums and answers for similar scripts to what I need. Can someone point me in the right direction here? Even just the proper terminology for what I’m trying to accomplish would get me a long way. What would be really great is if someone knows of a tutorial that walks through a similar mechanic to the one I’ve described. Thanks in advance guys.

There are plenty of ways you could approach this. A simple one could be as follows:

First, add a component “PlacementTracker” to each of your movable items that tracks whether it has been successfully placed or not. When the object is created have this set to false. When it is placed correctly set it to true.

Then whenever a movable item is correctly placed, look at all of the PlacementTracker components in the scene and see if they’re all set to true, which indicates that you’re finished. You can use “FindObjectsOfType” (look it up in the scripting docs for your language of choice) to get a collection of all of the PlacementTrackers to look at them.

Hope that helps!

That helps a ton. I’ll give it a try. Thanks so much for the info.

Hopefully you come back to this thread angrypenguin. I just read this in the documentation -
Please note that this function is very slow. It is not recommended to use this function every frame. In most cases you can use the singleton pattern instead.

Can I use this function without checking every frame somehow? Is there a less expensive way of checking for this?

Use FindObject when you start your scene, then save the result so that you can use the cached results without having to do the look up again.

This is kind of the place to have a game manager. When each object is finished it activates an add function in the manager. If the total gets to a certain number, the manager does something. You don’t need to use find at all. Just put a public gameobject variable at the top and drag the object onto it in the editor.

You don’t need to use it every frame. There’s no reason to do that. Only use it when the state of a PlacementTracker changes.

Also, as others have said, you can keep a list of them somewhere and use that list. I wouldn’t worry about it for something this simple, though. You don’t need to call it often at all, and finding them when you need them means not needing to maintain the list.

Thank you guys for your replies. Awesome forum. I’ve got a lot to go learn now. :slight_smile:

1 Like