How to use Components?

This article introduces how to use components. With components, you can easily create 3D objects for interactions and even more complex logic. Let’s get started!

What Is a Component?

Components are a special concept in Unity. Adding components to your GameObjects can make the GameObjects do the things you want them to do. Each component is a functional piece of a GameObject. Unity contains many built-in components, such as Rigidbody (enabling a GameObject to be affected by physical forces) and Audio Source (enabling a GameObject to make a sound). To learn more about the components in Unity, see the article at https://docs.unity3d.com/2021.3/Documentation/Manual/UsingComponents.html.

Similarly, ParaSpace offers a batch of components for users, for example, Para Seat (enabling a GameObject to be seated) and Para Pickup (enabling a GameObject to be picked up). These components will be described in detail later.

How to Use These Components?

ParaSpace provides 2 types of components. One type is the native components like Unity, which are called C# components, such as Para Object Sync. The other type is the components based on Lua scripts, which are called Lua components, such as Para Pickup and Para Seat. The main differences between the 2 types of components are:

  • They are used in a different way. C# components can be directly searched for and added in the Inspector panel. They are used in the same way as the native Unity components. For Lua components, you must first add the Para Script C# component in the Inspector panel and then mount the corresponding Lua script to the component. The following will describe how to use the 2 types of components in detail.
  • Whether they can be modified by creators. Although it is easy and convenient to use C# components, creators cannot view and change the source code of these components. However, for Lua components, creators can directly view and modify the source code conveniently.

How to Use a C# Component?

Directly search for and add a C# component in the Inspector panel of the GameObject to which you want to add a component. Take Para Object Sync as an example, you can add it in the following way:

After you add the component, modify the component properties directly in the Inspector panel. For the description of each property, see Para Object Sync. (As the SDK has been updated, the component properties may have changed. The SDK version described in this document is quite outdated.)

How to Use a Lua Component?

First of all, directly search for and add the C# component Para Script in the Inspector panel of the GameObject to which you want to add a component.

Then click the Attach button of Para Script to add the corresponding Lua component. The following figure takes Para Pickup as an example.

After you add the Lua component, you can directly modify related properties on the panel. For information about the properties of Para Pickup, see Para Pickup.

If you have already learned or known how to write a Lua script, you can also use this method to add your Lua script to the GameObject to implement various game logic. For more information, see Para Script.

Congratulations. You have completed the course on how to use components!