I'm trying to make an application that has sprites going down the screen with numbers in them. The Text(Script) component only works for 3D objects. I've tried using Text Mesh and making that a child of the sprites but I need them to be instantiated as a Prefab. So when I load the sprite in as a prefab it loses it's relationship to the Text Mesh. Does anyone know of a solution that worked for them?
There are many ways to do it depending upon your requirement. I will show you two of the most basic.
1- Use 2D Sprite and TextMesh.
2- Use Canvas Image and Text Objects.
P.S First one, that is 2D Sprite can be Instantiated directly in the hierarchy but for 2nd(Canvas Image) you need to instantiate it inside the canvas obj means as a child of canvas object.
Related
Currently, I'm developing a hexagonal tilemap game. Every tilemap is a player and I need to display their scores on them. How can I do this?
One way would be to create a prefab with your text setup (e.g. a worldspace TextMeshPro object), and then instantiate them using Tilemap.GetCellCenterWorld() to get the appropriate positioning for relevant tiles. Get the text object using GetComponent<TextMeshPro>() so you can change the text etc.
I want to make RPG game using Unity2d with the tile feature to draw the game map.
I created a new class inherited from UnityEngine.Tilemaps.Tile and overrided void GetTileData.
In void GetTileData I determine the sprite to show for each tile according to the tile's neighbors.
See the image below. The source image is input from the inspector. The input is only one image like this below. I don't want to make massive input images caus that totally mess up.
But then I have a problem. When in the game I have to extract certain blocks from the source image and combine them into a new sprite to show onto the map as a tile sprite.
Just want to know, if I have the 4 rectangles known, and want to combine them into a sprite like the image above, how can I do that?
There is no easy way to do what you want in code. Simply use a tilemap with smaller base tiles.
I created an animated prefab and want to use it as image in button. Is this possible? If not what can I do to insert an animated image in button.
I assume you are talking about showing an animated 3D prefab on top of your button.
If you have a 3D prefab and want it to be rendered on top of a button, you need to setup a separate render chain.
In essence you add a camera, that renders your object to a RenderTexture. Then you use this RenderTexture as source for an Image component on top of your button.
The critical part is setting up the camera and prefab, so that it doesn't render the whole scene, and isn't visible from whithin the scene.
There are many ways to do that, but I think the easiest way is to place the prefab and camera far away from the rest so that they are outside the view range of the main camera.
Just make sure the camera sees the prefab (and only the prefab) and has the render texture setup as render target.
I'm making a tile based board game (on a grid). In going about making the gameboard, the easy thing would be to instantiate all of the tiles in code, but then they only appear in play mode. I want to be able to edit the tiles in the editor, but I still want my tiles to be stored in a 2D array in my controller class. If I build the board in the editor, how might I go about loading them in at runtime?
Keep The Tiles in the Resources Folder Unity. At Run-time Load from the Resources and instantiate Tiles To Your Grid Positions in the Scene.
GameObject[] Tiles= (Resources.LoadAll<GameObject> ("Tiles"));
I am creating simple 3D editor. I now can draw simple primitives like cube but, I don't know how to save this object to som variable and then copy it to other coordinates. I also don't know how rotate/scale/move this cube and save this new shape to variable. I have seen many tutorials on this topic, but in every one them, guy is moving only camera, not drawn object(cube). So basically I just need tutorial how to save some object to variable, than load this object from variable and draw it many times on different coordinates over scene and apply some transformation to these new objects(move,rotate,scale). I am creating this app in C# and OpenTK
Use the GL.Translate(x,y,z), GL.Rotate(θ,x,y,z) and GL.Scale(sx,sy,sz) functions to move the coordinate system origin, orientation and scaling.
So drawing a cube after the command
GL.Translate(10,10,100);
will draw the cube at the above location. Here is an (clunky) example of this process below: