Accessing Other Components
Get and Add Components
Similar to Unity, accessing other components can be done through the GetComponent<T>()
method, as well as other component fetching methods, such as GetComponents<T>()
.
However, to fetch other AirshipBehaviour components, you must use the GetAirshipComponent<T>()
method, et. al.
The same applies for adding components, such as AddComponent<T>()
and AddAirshipComponent<T>()
.
Performance Considerations
Fetching components via methods such as GetComponent
and GetAirshipComponent
are expensive. Avoid calling these sorts of methods in per-frame code, such as the Update
method. Instead, cache the result of the call to a variable.
Alternatively, the above code could expose boxCollider
as a public variable, in which the variable could be assigned in-editor.
Last updated