Create game object from the texture in 2D - unity3d

I have some texture - a square picture with the painted bricks. And I want to create the element I will use as an obstacles - usual platformer's walls - in my game. So, I can't understand, how can I create this game object? For example, in 3D I can jus to create an object - for example, cube - and drag'n'drop my texture to this object. But in 2D I can't do the same steps. In 2D, as I understand, I need to create a new game object - sprite - and... what next? Drag'n'drop in this case doesn't work, sprite renderer has some fields I think I need to use - 'Sprite' and 'Matherial", but I can't understand, what exactly I need to do with my texture to have the ability use it here and how exectly I need to use it.

You mean this?
public Texture2D myTexture; // Assuming that it has been linked to a texture imported into your project by drag-n-dropping that texture onto this property using Inspector window
void Start ()
{
gameObject.renderer.material.mainTexture = myTexture;
}

In the image/texture import settings you can choose between many different options, for example: Texture or Sprite.
Sprite takes in sprite image
RawImage takes in pure texture
Image takes in sprite image.
Once you put the image to sprite mode in the import setting, you can then drag the image/sprite to the sprite.

Related

RenderSettings customReflection texture has invalid type, 2D given while only CUBE is supported. Custom reflection texture will not be used

so I started an unity project w ps1 graphics style, and it been smth like 2 days I have this error but the game still working kinda fine, can someone explain me why this happening? Thanks!
(Im not using URP)
Full error :
RenderSettings customReflection texture has invalid type, 2D given while only CUBE is supported. Custom reflection texture will not be used in UnityEditor.EditorApplication:Internal_RestoreLastOpenedScenes ()
In the Texture 2D Import Settings, change Texture Shape from 2D to CUBE.
In your project, click on your texture. Import settings are found in the inspector.
Cube defines the Texture as a cubemap. You could use this for Skyboxes or Reflection Probes
, for example. This type is only available with the Default, Normal Map, and Single Channel Texture types.
From the Texture Shape Reference of Texture Importer Documentation.

Unity TilemapRenderer draw mode sliced

Unity SpriteRender has a useful drawMode parameter to define how the Sprite scales when its dimensions change, with the option to slice sprite if correctly set in Sprite Editor.
Unlikely TilemapRenderer does not have this drawMode option, therefore it is impossibile to correctly slice a Sprite of a Tile.
The image below is an example of what I would achieve, the first image is the sprite itself, the second one is the tile (NOT sliced) the third one is a UI Image, where the sprite is correctly sliced (this is what I want to achieve).
Is there any way to have that result with TilemapRenderer?

In Unity3D How to Generate custome physics outline border points at runtime?

I'm trying to Generate custom physics shape outline points at run time in unity, so that I can use those points later on. currently I'm doing it manually through Gizmos points.
example shown in the images below [sprite without border points] is my sprite and expected output will be [sprite with border points] or [custom physics shape] something like this.
is there any solution to do custom physics shape outline point via code ? this will be very helpful for me.
sprite with border points
sprite without border points
You have to get the locations of the vertices you want to use, then you can use those vertices to create a Mesh. Once you have the mesh you can use it as the sharedMesh for a MeshCollider, which lets you use arbitrary shapes for physics collisions.

How to assign a texture around the edges of an object (as in the actual edges, not an outline)

I want to create a shader that assigns a texture to an object, then a different texture around the edges of that object (similar to an inside glow, or a "force field" but for all the edges in the object instead of the outline edges). Is this possible with shader graph? Or do I have to write a custom shader ?
ps: I want to do this for a single object, not the whole scene.
description :-
enter image description here
these picture were taken in blender just to demonstrate what I mean

Using a sprite to mask 3D objects in Unity

I have a png image that I want to work as a transparent mask, where it will be completely transparent in the scene but 3D objects behind it would not be shown (similar to a sprite mask, but needs to work with 3D objects).
So I added the image as a sprite (point - no filter) in my 3D scene and I have a shader already applied to the sprite material, but it is not working properly. Looks like the pixels are not being "cut correctly" in the borders.
I'm using this approach since the unity built-in "2D sprite mask" only affects objects using Sprite Renderer (as explained here https://docs.unity3d.com/Manual/class-SpriteMask.html), but I want it to affect 3D objects.
So this is the shader:
Shader "Masked/Mask" {
SubShader {
Tags {"Queue" = "Geometry+10" }
ColorMask 0
ZWrite On
Pass {}
}
}
This is the sprite to work as the mask (png image):
sprite mask
And these are the result that I want vs. what Im getting:
results compared
Im not good with shaders, so I would like to know if there is a change in the code that can be made in order to improve the result. I've already tried different formats for the sprite image (png, tif, compressions), but the results are the same.
I've done something similar using 'transparent' 3D occluders and render priorities, I imagine it would be similar with sprites...
Render non-occludable geometry (including Sprite) {"Queue" = "Geometry"}
Render occludable geometry {"Queue" = "Geometry+1"}
Strictly speaking, your occluder (the sprite) only needs to render to the depth (Z) buffer if it's always transparent.