4

I am developing an educational game where I give the user a selection of words. The objective is to take these words and arrange them into a sentence by dragging each word individually and placing it into order on the provided area. I have an plane ready for each word to be dragged onto, but I am unsure how to determine whether the user has dragged their word into the correct position within the sentence.

I thought maybe I would be able to give an ID/Tag to each word, and a relating ID/Tag to each plane. When the two collide I could compare the two IDs and if they match, consider it a successful placement.

I'm wondering if anyone else has a better solution, as I am not sure about the best way to go about this?

apxcode
  • 7,696
  • 7
  • 30
  • 41
caubry
  • 260
  • 4
  • 13
  • can you provide more info? The placement of words is related to exatly fixed positions on the plane? Shouldn't they relate to each other instead of a position in the plane (linking words like in a linked list or like in a jigsaw puzzle)? – Roberto Mar 31 '12 at 00:44

1 Answers1

1

Your idea is good, I don't see why not. Depending on how you implement this you can have much work if you have many words, right?

I suggest you this: make a prefab that consists of 2 colliders (and their respective GameObjects) and one script. One collider for the word and one colider of the correct position. The script would read from somewhere (a resource xml, field in the editor, etc.) and apply the initial position for the word and the position for the 'correct position' collider. This script would also read other information (like the actual word) and make all configuration of these objets.

This way you could easily drag 'word prefabs' to your scene and configure them individually.

Additionally, instead of dragging this prefab, you could have an external script in your scene that would represend that 'level' (if that concept applies to your game...). The idea here is that this script could load the prefabs for that 'level' during runtime. It could even pass all the data for the prefab script to configure the objects, like I said before.

I forgot to say the most important difference: in this method you don't have to worry about ID's. They belong to the same GameObject parent, so you can easily retrieve the objects you want in the script.

Roberto
  • 11,557
  • 16
  • 54
  • 68
  • Thanks for your answer. If I understood, I will need to create a prefab with 2 colliders and one script. What I ve already done it is created 5 GameObjects(5 Cubes with a word attached to each ones... so not random), added a script on them for the Drag & Drop and 5 white Planes(for the placement). They all have a rigidbody and so a collider. Now, you said that I should create a Prefab with 2 colliders. Do you mean I should include these 10 objects within my Prefab? – caubry Mar 31 '12 at 10:11
  • And because the Drag & Drop Script is already attached to my cubes and wont need to worry at this level. How would you call each individual object without any Tags or Ids? Thanks. – caubry Mar 31 '12 at 10:11
  • Hi. My idea is to create one prefab that represents one word with its correct position, that is, one cube with the word and one game object with the 'correct position' (the plane), so, 2 game objects, plus one script to control those 2 game objects and one more game object that is their parent (the prefab game object). Since they belong to the same game object parent (the prefab game object), they can easily find each other (GetChild(), GetComponent() ...), so, no IDs. This is a more monolithic, modular approach, that would help you to build many levels. – Roberto Mar 31 '12 at 11:00
  • If your idea is to have only one level (one 'phrase'?, one scene), then it's debatable whether it is worth to do my way. If all the game is about only 5 words, than tagging the objects and comparing is just fine and fastest to implement. – Roberto Mar 31 '12 at 11:05
  • Ok I understood it. I will try your idea. Thanks a lot. – caubry Mar 31 '12 at 11:38