What is a SpriteRenderer? (Unity Tutorial for Beginners)

What is a SpriteRenderer? (Unity Tutorial for Beginners)

Code Monkey

5 лет назад

72,127 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Code Monkey
Code Monkey - 24.08.2018 22:26

Question
When would you use a MeshRenderer instead of a SpriteRenderer?





Possible Answer
By using a MeshFilter and MeshRenderer you can do some really cool things with the mesh, you could still use a quad and dynamically move the vectors to create a wobbly effect or use a Texture2D instead of a Sprite and do some spritesheet animation by modifying the UV array.
My animation system works with Meshes instead of the SpriteRenderer so that I can dynamically create a mesh that contains a quad for each body part, that way the game only uses one game object to display multiple body parts that are animated.

Ответить
TheGrimriftstalker
TheGrimriftstalker - 01.12.2022 00:06

Thank you so much for this tutorial. This did wonders for a VN style game as well. Having backgrounds swap in and out is so much easier to call outside of script than anything else I've tried, and I've tried a LOT(previously I had gameobject as parents for each sprite and SetActive for each one, then worried about how I was going to disable them when I switched locations. Absolutely awful stuff.) So I truly appreciate this!

Ответить
Operacion Spartans
Operacion Spartans - 04.06.2022 01:41

Como se haría con objetos 3D

Ответить
Nathan Van Rooy
Nathan Van Rooy - 21.05.2022 01:35

how would i get the sprites to continually randomly generate? i was able to do it with 3d spheres but losing the little hair i have trying to get the sprites to do it.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class OmiSpawn : MonoBehaviour
{
public Sprite OmiSprite;
public float Speed;
public GameObject Omi;

void Start()
{
SpriteRenderer spriteRender = gameObject.GetComponent<SpriteRenderer>();
GameObject OmiGameObject = new GameObject("OmiGameObject", typeof(SpriteRenderer));
SpriteRenderer OmiSpriteRenderer = OmiGameObject.GetComponent<SpriteRenderer>();
OmiSpriteRenderer.sprite = OmiSprite;


InvokeRepeating("Generate", 0, Speed);
}
void Generate()
{
int x = Random.Range(0, Camera.main.pixelWidth);
int y = Random.Range(0, Camera.main.pixelHeight);

Vector3 Target = Camera.main.ScreenToWorldPoint(new Vector3(x, y, 0));
Target.z = 0;

Instantiate(OmiSprite, Target, Quaternion.identity);

}

Ответить
Dan H
Dan H - 16.04.2022 21:27

What if I want my burger to have different tints?
Like one have a red bun and purple cheese while the other has an orange bun and green cheese.

Would I need to have the parts of the burger as different sprites, or could I have one sprite with different tints?

Ответить
Darryl Wolfe
Darryl Wolfe - 11.04.2022 08:50

Q1. how to scale a gameobject with spriterenderer component inside another gameobject.
>When I try scaling with Recttransform component, it doesnt work. If I change the scale values, it works but the bounding box increases too causing it to have bigger size than the parent gameobject
>When I try scaling using Transform component, I can resize it manully to fit the parent gameobject but cant really make it accurete like what RectTransform can do using the anchor presets

Ответить
Eng. ahmed
Eng. ahmed - 24.02.2022 12:21

How to correct error (Sprite Renderer does not contain a definition for 'IsUsingDeforableBuffer' and no accessible extension method 'IsUsingDeformableBuffer'accepting a first argument of type 'Sprite Rnderer'......

Ответить
David Regalado
David Regalado - 08.02.2022 02:14

How can I change the color or sprite from a different object in the scene? Also great tutorial.

Ответить
Hafiz Ahmad
Hafiz Ahmad - 12.01.2022 17:05

bro i want to change multiple sprites , can i use a sprite[ ] array or is there another way to change multiple sprites to one object?

Ответить
Guy From Net
Guy From Net - 11.11.2021 21:38

the idea to make a video about sprite renderer is great,
but sprites examples are crap. People just wouldn't get what slice is for and why your pixelart ship looks blurry

Ответить
Peter Kim
Peter Kim - 22.10.2021 04:11

Very professional tutor 👏👏👏👏 I watched several tutors but you seem to be advanced so far.

Ответить
Heitor S. Filgueiras
Heitor S. Filgueiras - 20.08.2021 16:22

and i quote "our spaceship has now converted into a burger through code" coding truly is boundless

Ответить
Zetta
Zetta - 18.05.2021 19:02

I want to code a battle box in the game Undertale but I don't like how when the box resizes, the walls stretch as well.
Is there any way to fix this?
For some context, I have all four walls as Separate GameObjects and, all of the walls have the same parent object.

Ответить
LIC Universe
LIC Universe - 09.04.2021 18:45

If you use a bone type Sprite and we want to insert it in our Sprite renderer how are we going to do that

Ответить
Refluent
Refluent - 12.02.2021 04:59

So I get a character from the asset store, and I also got an animation, how can I combine them together to make a simple character movement animation [3d game]

Ответить
Rishabh Vishwamitra
Rishabh Vishwamitra - 10.01.2021 16:10

Now I know how to convert a spaceship to a burger

Ответить
Cyberguy Game
Cyberguy Game - 09.11.2020 00:03

How can I get this 1x1 sprite. I only have this other options.

Ответить
wEirDO is OP
wEirDO is OP - 01.11.2020 12:46

Dude, thanks.. omg how i can thanks u!!!!!!!!!!

u solved my problem cuz i am a beginner.

tnx tnx tnx tnx tnx

Ответить
green dragon
green dragon - 01.09.2020 09:58

i have a scroll view (1 X unlimited) , think ribbon, need to change the contents, 50 items, 10 item, ect... i have the different lists in a folder, so the code is the same for all, point to folder, for each sprite renderer, change the sprite, until no more sprites are left in the folder. what have i forgetten?

Ответить
Sahil Nambiar
Sahil Nambiar - 23.08.2020 04:57

I create the sprite and i can see it in the scene window but when i switch over to the game tab i do not see it at all even though it is in my camera

Ответить
Maxim Sur
Maxim Sur - 12.08.2020 13:08

Hello Monkey, I have a question. How can i disable sprite fully, like not in sprite renderer but to uncheck the checkbox which is above the "Transform" component and "Tag"

UPD: ohh, i got it
For everyone: you need to create a public GameObject in your script than put GameObject here and SetActive(false) to this GameObject
btw, ty for lessons, Monkey <3

Ответить
Aneta Roubíčková
Aneta Roubíčková - 15.05.2020 17:38

Great intro to SpriteRenderer! Thank you :)

Ответить
Preslav Kolev
Preslav Kolev - 06.05.2020 14:50

I can't see my sprite!!!

Ответить
Navaneeth Reddy Nalla
Navaneeth Reddy Nalla - 16.04.2020 15:40

What program do you use for making sprites

Ответить
Simon Áron
Simon Áron - 31.03.2020 18:14

i rate this 3 kohlrabis out of 5 cauliflowers

Ответить
Nguyễn Phong Huy
Nguyễn Phong Huy - 12.02.2020 18:35

When I had finished slicing my sprite and hit apply, it still displayed the full sprite. Did I do something wrong? I set my sprite mode to single and mesh type to full rect. The warning under the draw mode in the sprite renderer was also disappeared

Ответить
Water Cat
Water Cat - 12.01.2020 19:37

Monkey code do know how to make sheder codes ?

The reasons I don't make sheder graph from is because I need urp and the urp don't support multiple cameras and my game have split screen I don't want see eny thing pink

If fixed that problem I use urp from the sheder graph only

Ответить
Electromorphous
Electromorphous - 03.01.2020 23:22

A highly underrated channel. I can see it blowing up soon.

Ответить
dragonman101
dragonman101 - 27.09.2019 22:56

why do you use the letter "f" when referring to coordinates or values?

Ответить
nick hayes
nick hayes - 05.06.2019 00:56

anyone offer help? when i make png sprites from vectors and place them close to the front of the camera in my 2d unity document, the edges appear soft and blurry. anyone know how to keep them crisp?

Ответить
322ss
322ss - 25.08.2018 18:23

Hi, you advertise you Utils library in your videos- it looks interesting - but downloading it requires registration - are there any strings attached?
Like other than you keep log of who has downloaded it. I'm Asking since your create account doesn't tell anything...

Ответить
Shayanpoor X
Shayanpoor X - 25.08.2018 16:17

Why when i put an sprite in my game and scale it down it will be like pixels?

Ответить
간디
간디 - 25.08.2018 07:09

Can you make a tutorial about the 2D srpg(tactics) game?

Ответить
negrime
negrime - 25.08.2018 02:18

I know how you did intro for games

Ответить
iDmitryYakovlev
iDmitryYakovlev - 24.08.2018 23:07

How to render an image from disk (by path), which is not added to project?

Ответить
AramilAnakir
AramilAnakir - 24.08.2018 21:32

Hey code monkey! I really like your work but you got me curious about your utilities package you were talking about. I went ahead and signed in to download it and try it out, but the confirmation email is not comming to me. :( I've tried on 2 email service providers, checked spam and other folders. still nothing, after a few days (I've done it on 20.08 if I remember corectly). Could you check it out? That would be awesome! Thanks in advance and keep up with your good work!

Ответить
Honne Delta
Honne Delta - 24.08.2018 20:05

you chanel is super cool

Ответить