Comment on page
- 1.To make an object dynamic (such as a door, drawer, lever, or valve), add a Dynamic Object component to the object.
- 2.Select the object dynamic type by clicking on the icons located at the top of the script.
- 3.Choose the Interact Type for the dynamic object, which can be either Dynamic, Mouse, or Animation type. Once you've selected the Interact Type, the References section will change, requiring you to assign all the necessary references to ensure the dynamic object works properly.
The Target field refers to the object where all interactions will be applied. This can either be the current object where the Dynamic Object component is added or a parent object.hi
- 4.If you choose to use the Dynamic interact type, you must specify the limits and axes to determine how the dynamic object should be interacted with.
By using curves, you can specify the speed change when opening or closing the dynamic object. The curve should be defined between 0 to 1 values.
If you are using the Dynamic interact type, it is recommended to enable the Show Gizmos feature. This allows you to visualize how the limits are defined and verify that the dynamic object is opening at the correct angle.
- 5.When using the Mouse interact type, you must add a Hinge Joint to the object and assign the corresponding reference (if it's required).
It's not necessary to modify the values of the Hinge Joint, since the main values will be automatically determined by the dynamic object.
If you select the Drawer dynamic type, you can determine the min/max open limits by copying the position from the corresponding axis, as demonstrated in the image below.
The process of configuring a switchable or rotatable dynamic type is similar to the previous steps.
To use a custom unlock dynamic script, create a script that implements the IDynamicUnlock interface. By doing so, you will be prompted to implement the OnTryUnlock() method, which will be called when you interact with the locked dynamic object. Here is a code snippet for a simple dynamic unlock script:
public class TestUnlock : MonoBehaviour, IDynamicUnlock, IInventorySelector
public ItemGuid UnlockItem;
private DynamicObject dynamicObject;
public void OnTryUnlock(DynamicObject dynamicObject)
this.dynamicObject = dynamicObject;
public void OnInventoryItemSelect(Inventory inventory, InventoryItem selectedItem)
if (selectedItem.ItemGuid != UnlockItem)
// unlock dynamic object
If you interact with the locked dynamic object using this code, you will be prompted to use an item from your inventory. When you choose the item, OnInventoryItemSelect() will be triggered, which will unlock the dynamic object if the item is correct.
To use the dynamic unlock script, simply assign the reference to the script that implements IDynamicUnlock interface in the Unlock Script field.
A good example of using a custom unlock script is the lockpicking puzzle.