Unity 3D – Intro about attributes and events .

By | 27/05/2018

This will update your component into visual area of Unity.
Some public variables will be fasioned and change with your selected attributes.
The attributes can be used into programming using the [] .
The class can have on top this attribute and is follow by the code source.
this will add a url

this will block drag and drop your component to just once.

this will block remove the component depend it TEST.

You can remove step by step , but when you add this also add both this component and the TEST component.
Many attributes use sections used to separate and show infos , like:
show word Details

make a space into Unity Inspector

show the header like Stats

this tell is a multiline for text area

renders a flexible textbox with a scrollbar.

create a slider from 0.0 to 360.0 for variable circle_angle

will be hide the public variables

this will execute the code , for example: you can execute the camera follow even you don’t use play mode.

this allow to run code GiveObject by create a menu on
Tools – Give object – Do it

then when play and used it this will run GiveObject

this gets serialized even though it is private

This can be a good example when you use sprites and colliders.

Then you need to use them and need to tell Unity something about your code

… and will show on development like a warning message “This one is old”

This part of the tutorial is more complex and is about events:
This attribute tell Unity can serializable something ( like: using events system ) .

Example with one serializable event:

I named the script , class and variable for event just to understand how this works.
You can use anything else for event : read_event_player, read_heat, read
You can change the name of the script or the class for event.
You can add Listener into your script and use them
NOTE: You can add new listeners to event, but you cannot see them in Unity Inspector.
Example: use Start area of code to add this:

then create this to use it:

If you take a look on Unity Inspector you don’t see this , just the print of Debug.Log
This events part is old but is ofen used by users.
You can use C# events and not the Unity events .
The Unity events is super powerfull for Unity development and is easy to use them.
If not you need to have some custom code for this type of tasks.
You can use something else into events (but not more 4 args) :

and use it

This is a little tricky but you can pass anything you want with events system.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.