Unity - How to combine sprites into one - c#

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.

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.

Create a slash effect using image and progressively drawing

What I want
To create an effect like an slash in my 2D project. For that, I've an image in my assets already, and I want to draw it from top to the bottom, allowing it to be drawn in maybe half a second, progressively.
The idea is to draw it to create the effect of the slash itself, and the progressively mode is to "fit" the slash image itself, imagine the first one of the following link, that would be drawn from left to right.
To achieve that kind of drawing, the only thing that I've found is fillAmount for an Image, combined with the fillMethod.
The problem
The problem is that these methods are for the Image class, that it's not recommended for game drawing but only for UI.
Anyway, I've tried to do it this way, and I've not been able to do it, because the Unity environment didn't let me drag&drop my slash asset into the Image variable that I had created into my script. I thought that it may be because of the type of import, but also trying to import it with the other options resulted in nothing better.
The questions
Just answering one of these questions would solve my situation (or I think so):
How can I make Unity accept my image/asset into my Image object in the script?
Another way to create such effect using Sprite or GameObjects directly?
Method 1: You can use sprite sheet to create a 2D animation
1-1. Prepare a splash effect sprite sheet (an image map contains continuous action image), like
1-2. Change the sprite mode to multiple in inspector window
1-3. Slice the sprites in sprite editor
1-4. Multi-select the sprites and drag into hierarchy window, Unity will ask you to save this animation
1-5. You will get an animation GameObject
Method 2: If you can make it like a circular progress bar, check Radial/ Circular Progress Bar in unity3d

Unity Quiz Game image on questions

How can I input image to be my questions on my quiz game app. I've managed to have the image script but I can't see any images
Here is my code for the Game Controller which holds the data of the game.
Here's an image of the Game Controller
Game Controller will look like this
public Sprite quizImage;
public TSSimpleObjectPool answerButtonObjectPool;
public Text questionText;
public Text scoreDisplay;
public Text timeRemainingDisplay;
public Transform answerButtonParent;
public GameObject questionDisplay;
public GameObject roundEndDisplay;
public Text highScoreDisplay;
The problem is image does not show when i run the app. What is the problem?
"Image doesn't show" could mean multiple things. You really need to clarify.
But here are some quick fixes from my experience. (Common error: "Image doesn't show")
a)
Make sure you look at the parameters when looking at Unity. When you superimpose images in unity (ie putting a background with a image), it's a common issue that sometimes images cover each other. You have like 5 images/text in your picture... make sure your paying attention to z values.
b) You need to looking into prefabs. IE dragging an image into the hierarchy and dragging it back to assets usually does the trick. Get the prefab -> drag it into the public gameobject. Judging by how you haven't plugged in a sprite in your image means you can't to figure out how ton drag objects in.
Some documentation on prefabs
https://docs.unity3d.com/Manual/Prefabs.html
c) You're mixing up Sprites and GameObjects together. Look up differences between the two and post again.
d) Make sure you are not plugging in a blank sprite. If you want to use sprites, make sure you know how to attach to image to them. You can follow this tutorial down here.
https://docs.unity3d.com/Manual/SpriteEditor.html
Second of all, sprites are used in unity 2D, not unity 3D. They are 2D graphical objects... stop mixing up the two.
Hope this helped.

How to map skeleton to shape in C#

I am trying to write a Tetris game using Kinect. There are two game players. One of the game players will move the blocks and the other will define the shape of the blocks using body positions.
Now, the challenge I am facing is : How do I map the body position to a block?
For example I have this shape given below.
I want to identify it as a 'T' shape block. How do i Do it?\
Here is what I thot:
I will store sample images of all the blocks (total 10) and compare the skeleton image from camera to these stored images and then display the block to which the camera has a match.
However, this is the toughest part. How do I find a match? Even if I have a T shaped sample image, what processing do I do with this skeleton so that It resembles a T shape before the comparison can be done?
I would suggest using a gesture recognition library. Such as:
https://github.com/EvilClosetMonkey/Fizbin.Kinect.Gestures
http://kinecttoolbox.codeplex.com/
You can define the gestures as a static held position -- for example, "Menu" in the Fizbin.Kinect.Gestures library. When the particular gesture is recognized an event is fired and you can then act upon it, by showing the shape you desire.

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