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?
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.
Related
Ok Im trying to make a TALL pile of objects, ideally where the outer layer/ones touchable by the user on ground level have rigid bodies and are able to be moved.
Ive succeeded using https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=2ahUKEwjem72Awa3eAhWKEZAKHbHMCBcQwqsBMAB6BAgGEAQ&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DPJBPCnuaqIo&usg=AOvVaw1ewMypDbMyIV-qz8LZoo2e to make a shallow pile of objects that can move around, but no matter how many objects I drop in play mode, they inevitably bounce off each other and distribute out on the ground.
I need a TALL pile that won't all collapse - reducing polys as much as possible for gameplay, whats the best way to do this? Is there a way to use a particle system like I did with blender and a premade object:
How is this typically done in unity?
You will want to stack them in your scene, enter play mode, let them fall and come to rest then just keep going back and forth. Once you have a good stack. Clear all the random debri, then create an empty and drag all the items into it in the inspector scene view, then you can make the empty into a prefab and set pikes wherever you want.
Alternatively you can remove there rigid bodies and parent them to an empty and just add a simple block collider(if you don't want the column to come apart)
I am wanting to make a birds-eye view pixel-art game.
I currently have two sprite sheets set up, and split and whatnot
groundSheet and characterSheet these are split up into
ground_0_0_0 (A concrete floor)
ground_1_0_0 (grass)
character_0_0_0 (man idle animation frame 1)
character_0_0_1 (man idle animation frame 2)
character_0_1_0 (man run animation frame 1)
character_0_1_1 (man run animation frame 2)
character_1_0_0 (woman idle animation frame 1)
character_1_0_1 (woman idle animation frame 2)
character_1_1_0 (woman run animation frame 1)
character_1_1_1 (woman run animation frame 2)
The numbers after are a note as to:
first number - the main set of sprite animations (eg man)
second number - the animation set in use (eg run or idle)
third number - the frame of said animation.
(the ground has this as i plan to have animated grounds late on)
Now, I wish to make a script for the character (and ground alike) that has an editable value that is view able in the unity editor, for example how things like the sprite renderer has sprite, colour etc. Which dictates what first number to use (see above) what second number and the delay for the animation of the third number. This will then tell the sprite renderer what pictures to load and how quickly to load them. I also wish for the script to scan for the file starting with for example character_0_0_ and then count how many files after it, so it knows what to do when animating. I would like this script to be checking for a change in one of the variables viewable in the unity editor to change and as soon as it does it checks everything it needs for an animtion.
Something else could be done where there is only 1 box to edit in unity, which you put character_0_0_ or ground_1_0_ or something similar, and it checks everything that way (it also makes the script universal, and usable on the ground, character and walls (which I am adding later)).
This may seem confusing, but it make sense for me and many of you will probably mention a much easier way to do animations and such, but please only say these if it does what I want above.
For scripts and such my file layout:
/Assets
/scripts
ground.cs
character.cs
/sprites
characterSheet.png
character_0_0_0
character_0_0_1
character_0_1_0
character_0_1_1
character_1_0_0
character_1_0_1
character_1_1_0
character_1_1_1
groundSheet.png
ground_0_0_0
ground_1_0_0
(For some reason Stack overflow said the above was code, so i had to make it as that)
ground.cs and character.cs are the scripts in which I want to made as explained above.
In my object view thingy I have
Main Camera
ground
character
I am practically a newb to C# and JS I know bascially the grammar of C# (like where to use {} and put ; at the end of the lines). If you help me with this, i request that you explain the script, like use the // thing to simply explain what each command does, I know a few but not all of them. And I know someone is going to say it is really well documented in tutorial X and such, but most tutorials are not in unity 5 and while helping with the matter do not touch on it exactly.
Thank you for your help, if there is anything about this question/request that you do not understand (It is pretty complex) I will explain.
Maybe I am completely wrong, but it seems to me that you are trying to recreate an Animation system.
Is there a specific reason for which you wouldn't use Unity's animation system?
You can do everything that you describe here with it (change sprite, choose animation speed). And you would have almost no code to write. Just drag and drop you sprites in the editor for a start
EDIT - answer to first comment:
What you should do is create all the animations you need. Then in the animator, you choose which condition will trigger a transition to another animation (for instance, boolean jump is true will transition to animation jump). Then in your code you can call GetComponent().SetBool("Jump", true).
To have different character, you can create different gameObjects (one per character). They all have a different animator with animations specific to the character.
The other solutiojn if you really want one one gameObject and one animator is that you also add string condition to you animation (example, if character=="character1" and jump==true, transition to jump animation).
If I were you I would really focus on testing and learning all you can do with Unity animator. I can't think of a case were you would need to recreate the animation system yourself
Your question was long winded and hard to understand but ill try to help,
firstly if you want editable values in the unity editor I would Suggest using a serialized structure of information like this
[System.Serializable] // this makes it viewable in the inspector
public struct Sprite_Manager;
{
public Sprite[] Render_Sprites; // array of sprites to store sprites
public SpriteRenderer S_Renderer;
public float Anim_Delay;
}
public class Character : MonoBehavior {
Sprite_Manager SMG = new Sprite_Manager(); // instantiate a new instance of the struct
void Set_Sprite()
{
for(int i = 0; i < SMG.Render_Sprites.Length; i++)
{
SMG.S_Renderer.sprite = SMG.Render_Sprites[i];
}
}
void Update
{
Invoke("Set_Sprite", SMG.Anim_Delay);
}
}
Not sure if this is exactly what your looking for but this is one way you could setup a structure of sprite based information and use Invoke to setup some sort of delay when passing new sprites to the renderer.
after some fine-tuning on my game's GUI I am finally ready to begin with the gameplay. But that's a tall order. My game will be something like a 2D platformer with RPG elements like collecting armor, helmets, weapons etc. So with that in mind I begun thinking about a way to create my player. First, I thought a single Player class would do the job for me but since I want to equip the armor/helmet I've acquired, I quickly abandoned this concept.
Next I got another idea. I could have the player's Head, Arms and Legs to be different classes and each of them drawing its own texture, respectively. So I can swap between different armor/helmet sprites for each of the body parts. But that would seem pretty complex to implement... or not?
Could I have a code example on how you would do this? Which path you would take if you are in my stead? Single Player class or different body parts classes? If the latter, how would you hook them so that it all looks like a single sprite?
Armor/helmet should be part of the character status as it could be Health points. If you get hit your HP goes down and if your character collides with a helmet item then you should flag that status into your player object and render your character accordingly.
You may want to use the game component pattern (link is a very good read).
You probably want the player class still be the main base of the character, and have armor/clothing components that draw on top of the character.
The player class can then "have" the components and draw accordingly, add HP or other logic you like etc. A component could "break" and disappear etc.
I'm trying to create an auto spawned of game object out of predefined prefab.
The prefab contains a polygon collider.
The spawned instantiates the new object right at the end of the previous one, in a way that it looks like a single piece.
I'm trying to understand how to merge both of their colliders to be like a single polygon collider defined on the merged object.
Thank you for helping.
Btw if there's a code involved (which I'm sure there is), I would be glad if you could write it in c#.
Thank you!!
So from reading your Q and information provided i would say that you want one polygon collider to be exactly on the other. If this is your goal, when they collide, you can us the transform function and move it to the exact position of the other.
I'm looking for some idea's on how to create the 2d layout (walk path) of a game.
The tiles will be 32x32 pixels aswell as the character moving on the tiles.
I've thought of two ways currently, havn't tried any of them out yet.
The game will be shown in a window of about 400x300 or 512x356 something.. not much bigger than that where the game map itself could be bigger then 1000x1000. So only a portion of the map will be visible most times.
So here's my 2 options as far as I've thought of them.
[1]: Create the entire map at the start (which might increase the loading times but it will make it more easy to move the map around) including each object, player, enemies etc etc.
[2]: Create only the map seen and 1 tile around it (which is not visible) so I can make that one visible with a story board and remove the row / column which is out of bounds and create a column again.
Which means, If I have a room of 5x5 tiles, and I load 7x7 tiles. If I move right, I move all the tiles left and keep the player in the middle of the screen. Then I remove the far left set of tiles and create a new set of tiles on the right side, which will hopefully be done before the storyboard has finished moving.
In the second method all I have to consider is objects that are larger then 32x32. How could I best react on those.. However, this is a problem I'd like to address later.. Right now I prefer to know people's opinions and possible better methods.
I do apoligize if this question is no apropriate for stackoverflow.
Just be careful with the "load" word. Loading, means taking the data from the disk/drive and putting it memory. For that, you should load all the current world/map at once, before the game start. Trust me, you don't want to get yourself in dynamic loading stuff while the map is running.
But you only need to load the definition of your map, you don't need to create the instance of the object at that point. So you can create the instance from the map definition as the player walks... but are you really that constraint in memory? I can understand that for a game like Minecraft or Terraria where the map contains virtually millions of tiles... But for 32x32, you can consider making them all when you load the definition.
Of course, whatever the solution, you should only draw/compute/collide/update the tiles that are visible on screen.