There's plenty of tutorials which explain how to add and manage image objects. But what if I want to add simple rectangle with plain white color? May I do it similar to adding 3D objects? I see no rectangle option under 2D Object in GameObject menu.
I know that I may do it by script, but isn't there any simpler solution? Or maybe I should use 3D Object Cube instead?
For a rectangle (ie a 2D cuboid) you add a 3D object that is a Quad which is a 3D object with a size of 0 in one plane, in effect making it a 2D sheet.
See also:
http://docs.unity3d.com/Manual/PrimitiveObjects.html
Quads are most often used as backdrops to 2D games. Once you have the quad you can then change its material properties to set it as a single plain colour.
Related
I want to be able to draw any 2d shape dynamically in 2d world. My games has moving elements, looking like circle when alone, that can fuse and make complex shapes when getting close together. The elements can still move and thus separate or modify the shape.
How can I draw that with Unity? I don't think the usual sprites can do the trick.
I believe you can do that with shaders (sounds complex to me, but utilises GPU).
Or...
Modify sprite's vertices to introduce streching of the texture.
I want to use these cubes in my own game but I have literally no idea how he got them. Look at the cubes with the black outline, the walls the ground the roof, how do I get a cube with the outline like that. I know this is a stupid question but I have tried but I cant find out why.
Thanks in advance!
Those are not individual cubes.
Take as example one of the walls, probably it's a single cube (rectangular prism) for each wall, the trick is that it has a material with a texture applied to it and a normal map.
In simple words:
A texture is an image containing the colors the object has. In this case the blue color of the walls and the black lines simulating cubes.
A normal map is something like an image but it contains information about the "depth" of each pixel in the image. In this case it indicates that the black lines should be "deeper" than the rest of the image.
A material is the object that combines the texture with the normal map and along with other settings can tell the computer how exactly it should look like.
Of course this is only a very brief definition, if you want to know more about it I recommend you to read about: Materials, textures and shaders in Unity. There are some tutorials in Unity web page.
Use photoshop to create a single tile of each type of block and use it.
I'm building a visual city in Unity 5 and I used some textures for my buildings. But the problem is whenever I adjust a texture a cube ,it sets all of the sides of the cube to that texture.. I mean I want to remove the roof side texture because there's no building in the real world which has windows on the roof ! As you can see in this image:
So how can I remove texture from the top side ?
Daniel is right. And there is another way to achieve that is add a plane on the top of the cube.
To accomplish this you're going to have to do something called UV mapping.
Short answer is that this isn't possible with a regular cube in Unity, you're either going to have to create your own model, or some code to generate a mesh within Unity
http://answers.unity3d.com/questions/306959/uv-mapping.html
Either you know how to manipulate atlas texture or the simple call is to
Place a quad on top of that face of the cube (you could actually make a new cube of 5 quads or less)
Cut the part of the atlas map
Create a new texture and assign it to a material
Apply that material to the quad.
Then you can swap the texture of that material without affecting other faces.
First of all, I am using Unity3d.
What is the most efficient (in terms of memory) way to create a group of 2D tiles with 2D colliders using a texture atlas (and tile data)?
Background Info:
I am working on a 2D terrain generation asset. It is a very similar generation style to Terraria's random generation. Currently, each tile is being instantiated as a separate GameObject. As I now know, this is extremely inefficient, and I should use a texture atlas and tile data instead. Here is a link to a tutorial I have been following that deals with this in 3D: http://studentgamedev.blogspot.co.uk/2013/08/unity-voxel-tutorial-part-1-generating.html
The problem is that mesh colliders are 3D colliders; 3D colliders CANNOT collide with 2D colliders. Currently in Unity, there are no 2D colliders (that I am aware of) that have the properties of a mesh; I need to dynamically change the 2D collider to adjust to the positions that contain tiles. How am I supposed to develop an efficient 2D tile system using 2D colliders?
Here are some of my ideas of techniques that may work:
Add a box collider 2D component to the chunk GameObject for each tile in the chunk.
Somehow dynamically use a polygon collider 2D to stretch over all solid tiles.
I have read through several threads and cannot find a good approach for this problem.
I am mostly looking for a proven technique/approach to this issue, but I am open to any suggestions or techniques. I am happy to provide clarity as needed. Thanks for any answers! I appreciate the time you put in to answering my question -it helps a ton!
As you rightly said, 2D colliders do not work with 3D colliders. The correct approach would be to pick one or the other.
If you are mixing 2D and 3D objects, go with 3D. You can restrict the axes in which your objects are affected by physics as explained in this answer.
What is the proper way of creating 2D Mesh with collider?
All I want to do is create some shapes (not very simple like triangle or rectangle) like slide or rounded rectangle. And I want to define a repeating pattern inside it to fill and reduce memory. Lastly I will need a collider around my shape.
Create the entire thing in a modeling program like Blender... same as you would for a 3D model, but all of your shapes/meshes will be flat. Create your textures the same also... all in your modeling program. Then save your file (.blend for Blender) to your Unity assets folder. Now switch back to Unity and drag/drop the prefab that is created form the .blend file on to your scene. Change the renderer if you want (I use Mobile Unlit, or Unlit Transparent most of the time).
Works just like a normal 2D sprite now... but the texture will repeat and you can make whatever shape you want in your modeling program.
For the collider, you can add any type of collider you want. If your shape isn't standard, you'll probably want an Edge Collider 2D or a Polygon Collider 2D.
I would suggest you the following:
Create a polygonCollider2D directly in unity as you need it
Add a mesh filter and a mesh renderer
Add a custom script made by yourself, in which you convert the Collider polygon to a mesh (Mesh that will be used on your MeshFilter at runtime).
3.1. In order to do this, just copy the vertices of the polygon
3.2. Use the triangulator class in this link to help you create your mesh (http://wiki.unity3d.com/index.php?title=Triangulator)
Enjoy
If you want to see the custom script find it here: http://answers.unity3d.com/questions/835675/how-to-fill-polygon-collider-with-a-solid-color.html