P
P
piffo2020-05-14 23:38:52
C++ / C#
piffo, 2020-05-14 23:38:52

Classes in unity c#?

New to both Unity and c#. So do not judge strictly)
Now I'm studying classes. In theory, everything is clear, but in practice it is worse. I'm currently doing my first project - a 2d pixel platformer. The idea is simple, each level is visually the same, but the passage is different. I would just like to ask you to give examples of the use of classes on this project.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita, 2020-05-15
@piffo

Answer to the reformulated question from the comments on Dance Macabre 's answer :

I would like to receive an answer about the use of several classes in one script.
In Unity, you CAN describe as many classes as you want in one script.
BUT a class inheriting the MonoBehavior class or an inheriting class in the "genus" of which is MonoBehavior , there can be only one such class, but along with it in the script there can be a bunch of other classes that do not have MonoBehavior in the genus.
And now briefly to your question:
How to use classes? ...
Let's keep it simple, let's say you need inventory.
You are writing an Item class that has properties Name, Type, Icon, SerialNumber, etc. - let's say properties common to all kinds of objects in our inventory.
You, if anything, do not have to inherit MonoBehavior , but this is a separate issue.
Although in this case you can pay attention to inheritanceScriptableObject.
Then you write the Weapon class, and you inherit from the Item class. And in Weapon you describe properties like WeaponType, Damage, Range... Although, I just repeated it by analogy with any textbook... I don't know how to explain it better to you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question