|
I have a few question and appreciate if anyone can help out.
*edit as my question are not very clear. sorry about that
(comments are locked)
|
|
I guess the main idea would be to create prefabs/puzzle pieces that can be collected and then check to see if all have been collected? You could probably achieve this by making the puzzle pieces check for collision with the player (meaning player has walked into them/collected them) using the OnTriggerEnter or OnCollisionEnter function. This could look something like:
This will check if the player has walked into the puzzle piece, then add one to the total collected pieces variable, then destroy/remove the puzzle piece and finally if all pieces are collected go to the puzzle scene. Let me know if anything in the code is unclear or if I misinterpreted your question :) hello merry_christmas, thank you. you are right. i have actually figure out how to do it already. What bother me is the matching of the puzzle part. As mention, i am creating chinese game, so it will be quite different from the normal jigsaw puzzle which requires alot of pieces to form it. So for my case, i only need two or three to become a "complete" puzzle. http://imageshack.us/photo/my-images/404/post005.png/ -> required player to find a missing piece. http://imageshack.us/photo/my-images/839/post05.png/ -> missing piece that player have found. So i am headache how to match the two pieces correctly. As players will be collecting quite a number of pieces, then go to the scene and match it with the piece they collected. Any ideas how i can do it? thank you for spending time to help :)
Mar 05 '12 at 02:12 AM
missypooh
Hmm, so you'd need each pair to have a different id, but the two matching pieces to have the same. Are all pieces instantiated as the same prefab or have you created a prefab for each image/piece ? If you are instantiating all pieces with one prefab and setting each ones texture via script then you could also give them individual tags, for example pair-1, pair-2, etc. You could also use tags if you are creating a prefab for each though..
Mar 05 '12 at 02:27 AM
merry_christmas
ok. So after doing all this, how to do the validation part? Like comparing the tag they have? And usually when forming puzzle right, we will drag the piece to the respective place right, how to drag the puzzle piece to the position?
Mar 05 '12 at 02:44 AM
missypooh
To do the drag part you would have to check the mouse position and set the puzzle pieces position accordingly, here are some links that might help: http://answers.unity3d.com/questions/32807/instantiate-object-at-mouse-position.html and http://unity3d.com/support/documentation/ScriptReference/Camera.ScreenToWorldPoint.html . Then perhaps check if a piece is touching another using OnTriggerEnter and then check if both have the same tag name. Perhaps like this: OnTriggerEnter(Trig : Collider) { if(Trig.gameObject.tag == gameObject.tag) { //both pieces have same tag/are fitting pieces } }
Mar 05 '12 at 03:00 AM
merry_christmas
(comments are locked)
|
|
You can use this to check the distance between two objects:
Add this to each puzzle prefab and set the variable other to the player object in the inspector view. Don't quite know what you mean with the puzzle pieces, hope this helps with question 2 though :) hi thank you. I will try it out. Regarding the puzzle piece, it is quite similar in playing jigsaw puzzle. So in the beginning, i will show the players all the missing pieces for the jigsaw puzzle, so the players have to walk around the maze to find the missing piece. Any ideas how i can go about doing it?
Mar 04 '12 at 05:41 PM
missypooh
anyway regarding this code, where should i put it to?? The player? and the code i should put it in the update function?
Mar 05 '12 at 02:58 AM
missypooh
(comments are locked)
|
|
Afraid I can't edit the answer directly so here it is again: Add this to the puzzle prefab and set the variable "other" to the player object in the inspector view of the prefab.
(comments are locked)
|
