How to display text on Tilemaps - c#

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.

Related

Text on Sprites in Unity

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.

Unity - How to combine sprites into one

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.

Coloring blank Unity3D mesh of molecular compound by element

My team is building an augmented reality chemistry app.
We have successfully imported a 3D mesh of a molecule from wolfram mathematica using a special library...however, the way we are doing it only imports the mesh -- there are no colors on the molecule that show which elements are which, like this -
Is there some way to either:
Get skins for chemical elements/compounds dynamically with an API or save them as assets?
Be able to consistently identify the order of the spheres in Unity3D and map the proper color to it using JSON data I know I can get of the location/order of elements in the compound?
Some other way I haven't thought of, or a mix of the two above?
Thank you for any help.
You can try filling in the Mesh colors by using Mesh.SetColors in script. This will store a color for each vertex in the mesh data. I am not sure how you are processing your mesh data, but I am assuming you are already using a script to do this. Make sure you assign a material with a shader that actually reads and displays the vertex color to the screen

Unity layers not working as I want

So I'm very new to Unity and creating my first 2D game, It will have a player, monsters, platforms and a static background image.
So What I've done is set a 2D sprite as a background image which is on the default layer. I also got a character from the asset store that I just pulled in to the game and set to User layer 8 (player).
The platforms randomly spawn on the map and was not visible through the background at first but when I set the sprite sortingorder to 1 they were visible.
Now for the monsters. They are also from the asset store but inserted into the game via C# code. If I have a the background on screen they are still not visible even if i set the GameObject.layer = 8 for them(to same layer as player). Why? What Is the problem here.
Thanks in advance.
Unity has two types of layers, the ones you're changing are not the ones that determine drawing order, you need to change the SortingLayer and OrderInLayer parameters in the SpriteRenderer component.
https://unity3d.com/learn/tutorials/topics/2d-game-creation/sorting-layers
If you're only using sprites then you can keep all of them in the same SortingLayer and change the OrderInLayer of the background to something like -100.
If you're using 3d models, youre gonna need to manually set the positions of the objects closer or away from the camera (and keep all the sprites on the default SortingLayer).

Save cube in variable and apply scale/rotate/move OpenTK

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:

Categories

Resources