Movable Clickable Object
VKC Item Object is an Item, not a Node, so the click detection method GetNodeIndexByName described in this manual cannot be used. However, it is possible to achieve a movable object with click detection in VketCloud using a different approach. Follow the steps below:
Setting Up the Floor
- Create a Cube and name it "Floor".
- Set the Scale to
100, 1, 100
. - Set the Position to
0, -1, 0
.
Outputting HEO and HEM
- Create an empty GameObject named "Root".
- Create a Cube as a child of Root.
- Add an
Animation
component to Root. - Create an AnimationClip that makes the Cube move left and right.
- Right-click on Root and select
VKCHelper > Export Motion
. - Save the created HEM file under the Assets folder.
- Add a VKCNodeCollider to the Cube and set the
ColliderType
toClickable
. - Right-click on Root and select
VKCHelper > Create VKCObject
. - A Root_VKCItemObject will be generated. Root is no longer needed, so delete it.
- Turn on
ScenePreview
for the generated Root_VKCItemObject. - Set the object mode to
Motion
. - Drag and drop the created HEM file into the Hem field.
- Turn on Loop.
Placing a TextPlane for Click Confirmation
- Create an empty GameObject named "Text".
- Add a VKC Item TextPlane to it.
- Since it is hard to see as is, set the Position to
0, 2, 0
. - Set the text to
count: 0
.
Setting Up HeliScript
- Right-click in the Project pane and create a new HeliScript.
- Paste the following HeliScript:
component Sample
{
Item target;
int count;
public Sample()
{
target = hsItemGet("Text");
}
public void OnClickNode(int NodeIndex)
{
count = count + 1;
target.WriteTextPlane("count: " + count.ToString());
}
}
- Add a VKCAttributeScript to Root_VKCItemObject.
- Click the + button on VKCAttributeScript and select Sample from the selection button.
BuildAndRun
When you BuildAndRun, it will work as described above. Clicking on the moving Cube will increase the click count on the Text.