Confused about Meshrenderer renderer

Hi, sorry if this is a stupid question but I’m a bit confused: why do we type Meshrenderer renderer instead of Meshrenderer = renderer or something like that? Can other variables be declared without = signs as well? This is my first go at coding so maybe I missed it earlier but I can’t figure it out.

Thanks for any help in advance!

Welcome to the community @Treister

This is how we define variables in C#.

MeshRenderer renderer;

In this case, we are saying that we want a variable called renderer and it must be of the type MeshRenderer. The name of the variable can be anything as long as it’s not a word reserved by C# and it doesn’t start with a number. So, we could call it anything

MeshRenderer myVariable;

We need a variable before we can assign values to it

MeshRenderer renderer;
renderer = GetComponent<MeshRenderer>(); // for example
3 Likes

Thank you very much @bixarrio for your prompt and detailed reply! I think I understand a little bit better. I imagine as the course goes more depth will be explored and more things will make sense so I’ll mark this as the Solution. Cheers!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms