Hello, I might be missing something, even after reading the read me and playing around in unity I still do not understand the way hotspots work for the minigame. If anybody could tell me how to fix the problem, that would be swell.
I am using the Puzzle Template: Item Arranging from the downloads page.
I want to give multiple items the same solution area. Think of it as having 2 slots, red and yellow and then putting all the red items in the red slot and all the yellow items in the yellow slot.
In the manager scripts you assign a solution hotspot for each item, however, it seems that despite being able to give multiple items the same hotspot, multiple items cannot share the same hotspot in game. I tried in the example to assign the green ball to have the solution red slot and kept red ball's solution as red slot. What happens is only one ball is able to be at the hotspot at a time and the other one is kicked out. Which also means there is no way to solve the puzzle now.
Then I tried simply making the hotspots bigger, and a square when I made a puzzle from scratch. The items do not kick each other out, but they also don't trigger the complete cutscene, despite the hotspots being set to trigger. I do sometimes get one 'red' and one 'yellow' item to stick in the correct areas and the items of either color seem to want to bunch up in piles together, but that doesn't seem to impact anything. It is also worth noting that all the objects and hotspots were made by duplicating the puzzle assets and therefore should have worked because the original items worked. All assets are also listed as elements in the manager and all items have solution spots selected.
Is there something I am forgetting to assign or a way I need to edit the script to allow multiple items to share the same hotspot?
I'm torn between thinking the root of my problem being the manager not accepting what I'm giving it as a solution, and the root of my problem being something coded into the hotspot slots, and I'd like some input before I try messing with it further. Thanks!
(Also, I did try to just make like 20 identical 'red' and 20 identical 'yellow' hotspots to see if assigning individual hotspots would bypass the problem, but all the hotspots just made it impossible to drag the items around at all. So, uh, didn't work.)
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Welcome to the community, @Kafluffle.
The Arranging Puzzle template is designed such that a "slot" can only be occupied by one "piece" at a time.
On a technical level: when a piece is placed on a slot, the slot Hotspot is de-activated, preventing further interactivity until the piece is removed.
Also, when a piece is placed on a slot, it is positioned at the slot's centre - so even if multiple pieces were allowed, they'd all be laid on top of one another.
As it's a downloadable extra, it is possible to modify its scripts without affecting AC itself. However, I'm not clear enough on your intent to advise if this should be necessary. If you can elaborate on the way you want your own minigame to work (screenshots/mockups would be ideal), then I can let you know the best way to approach it.
@ChrisIceBox Thank you! And thank you for your swift response.
Basically, for my game there is a puzzle where you look inside a paper shredder. Inside the paper shredder are scraps of paper and scraps of money. You need to sort out all the scraps of money from the shredder and upon completion you obtain a pile of money scraps to be used in another puzzle. Because it is a pile anyway the laying on top of each other aspect isn't really a concern of mine.
https://imgur.com/PPDePbJ (General idea game mockup)
The way it was set up is that the left side has all the paper and money scraps and is the paper slot, so all the paper needs to be in that zone for the puzzle to be solved. Meanwhile the right side is the money slot, so all the money scraps need to be dragged there for the puzzle to be solved. This was to prevent somebody from solving the puzzle just by moving all the pieces to the other side of the screen.
So, in a simple sense I just need a way to split the screen in half, with one half checking for paper scraps and the other checking for money scraps. The drag system works well for moving the scraps, it's just the check for completion that is the issue.
Additionally, I am not sure if this would impact the code or not, but I do have around 45 unique money scraps drawings and a few additional paper scraps drawn, and my intent was to basically use as many assets as possible to create a full looking paper shredder to sift through once I actually got the code to work. In which case pieces correctly snapping to an area out of the way after being selected may assist players in getting to the correct pieces / alleviate the issue of selecting the wrong piece which may be frustrating.
Thanks!
Thanks for the details.
In this case, it might be best to avoid the use of Slots and just rely on the Pieces - which give you the drag-and-drop behaviour - as well as a simple script to detect if the scraps are all where they should be.
This script, ScrapSorter.cs, should do it:
To use it, attach to an empty in the scene, and assign the scraps in its Inspector (this can be automated further, just test for now). For any scraps that should be placed on the left: give them a specific Tag, and assign that Tag in this script's Inspector as well. Also assign an "X Threshold" (the position on the x-axis that divides the two partitions), as well as a Cutscene to run when the game is "won".
@ChrisIceBox Thank you, so, I don't know C# at all but did my best to work with this script, unfortunately I am still having issues with detection.
I did have to change the script because I was getting an error message which wouldn't allow it to run, and that is discussed in the script section. I figure my messing with the xposition in the script to stop an error is why this doesn't work, but since that was the only solution to get the script to run at all that I found, I'm at a loss.
The issue, as far as I can tell lies with the xThreshold, but I have broken down everything I have done in case that helps. Thanks.
Scene Information
All 'scraps' are duplicates of the pieces object, as we established that gives the drag and drop behavior. The only changes I made to them were changing their sprite image and assigning them the 'Left' tag.
I am using both the arranging puzzle manager and scrap sorter scripts.
If I only use scrap sorter and shut the arranging scripts to off on the objects the objects are not draggable. If the arranging scripts are on and there is no puzzle manager, I keep getting an 'Object Reference not set to an instance of an object' error. With both scripts enabled and the scraps assigned as scraps in the scrap sorter script and as pieces in the arranger puzzle manager I am able to play the game without errors.
There are no slots assigned to the arranging puzzle manager.
Win cutscene is tied to the scrap sorter script.
X Threshold and Gameplay
I can move the scraps around, but they do not correctly detect the scrap script that should tell them they are in the right place.
This is entirely reliant on the x Threshold as I can get the results to change by messing around with the numbers, only they do not make sense to me in a reasonable way.
If xthreshold <= 0 | I cannot win the game
If xthreshold = any positive number | If I pick up one piece and place it down in the same location, I win the game.
I have tried testing by starting all the pieces with a negative X starting position and again with a positive X starting position, no matter where the pieces start in relation to the threshold, or where I drag them, or what the threshold is I get the same results.
Script
I had to fix xPosition because xPosition was a Vector3 and wouldn't let me compare it to xThreshold in the bool. This solved the 'vector3 cannot be implicitly converted to a float error' and allowed me to actually run the script, but it might also be the reason the threshold doesn't work.
Here is the code with my edits below. Thanks.
`using UnityEngine;
using AC;
public class ScrapSorter : MonoBehaviour
{
}`
Good spot about the code error - apologies.
What the code does (or is intended to, at least), is check the positions of all the assigned "Scrap" GameObjects. Only if all the left-tagged objects are left of the threshold, and all others are on the right, should the game be considered "won".
I'd suggest starting with just 1, then 2 or 3, objects assigned in the Scraps field. Ignore the others for now, and check the exact behaviour you get with those.
@ChrisIceBox Okay thanks, so here is the current situation. I'm at a loss if you have any insight.
Testing with only 'left' pieces.
I get the same issue no matter how many scraps I use.
For example, if I have a scrap at x=8 and the threshold at x=1, if I move one scrap to x=9 (or anywhere else) I win. Which means it disregards the threshold, as 9 is not to the left of 1.
Even with one scrap, if x is 0 or lower it won't detect anything.
Testing with a Left and a Right piece
One of each piece, one tagged right, one tagged left.
If both are assigned in scrap sorter AND arranging puzzle manager, I cannot get the game to win regardless of threshold.
If the 'right' piece is in arranging puzzle but not scrap sorter, I can win by just moving the 'right' piece into the left side.
Replace:
with:
@ChrisIceBox !! It works now! Thank you!
head in hands okay one slight problem, probably an extremely easy fix given the game works now, but well, uh,
You wouldn't happen to know why, if the scene is the only scene in the panel and I play the game it works flawlessly, but if I incorporate the scene into the actual game, using a scene switch to get into the game scene, the game still works, however on start all the pieces are in the bottom left in a pile instead of their assigned positions.
It only happens when it is attached to the game. It is summoned with a scene switch. The player position is off camera, the OnStart cutscene turns the inventory and ingame menues off. All those things work independently so it should be an outside force attached to the rest of the game that throws off the start position??
Man, I'm really bad at this, thanks for your help.
What are the exact positions - shown in the Transform Inspector - of the pieces when they start in a pile?
Take one piece, and test removing its Remember Arranging Puzzle Piece component, if attached.
When they start in a pile they are at (X,Y) (-9.72, -5.47).
Removing the remembering arranging puzzle component fixes the problem.
I don't understand why remembering is an issue in game and not when the puzzle is on its own, but what's important is now it works for my purposes. Thanks!