en:vci:sample:onuse:no3

Play an animation on grip button press

This article was written for “UniVCI-0.15.”

Example data

https://virtualcast.jp/products/9bd2f446cc30815fd18fa7e66b7cd62e0b8dc43cb666d435e5474ab224888bfe

To execute a process when the grip button is pressed, use “onUse”.

In this example, we will create a process that plays an animation
when the grip button is pressed against a certain “VCI SubItem”.

1. Create a new GameObject and create a Cube as its child.

In this example, we named the GameObject “UseAnimation_VCI,” but it can be anything really.
Let's name the Cube “Cube.”
Specify Y-axis value of the Cube to 1 so that it doesn't go through the floor.

2. Attach an “Animator” component on the Cube,
Create an “Animation” and associate it with a state in the Animator.
Name the Animation file “UseAnimationAction”.
* Refer to Unity manual for the details of manipulating an Animation.
https://docs.unity3d.com/2018.1/Documentation/Manual/animeditor-CreatingANewAnimationClip.html

3. Attach a “VCI Object” component on the GameObject,
and attach the “VCI SubItem” component on the Cube.
When doing this, “RigidBody” components are also attached automatically.
As the Cube won't be using gravity, turn off Use Gravity and turn on Is Kinematic.

4. On the VCI Object component in the GameObject, set the Scripts Size as 1.
Enter “main.lua” in the Name and paste the script shown below.

main.lua
function onUse(use)
    if use == "Cube" then
        vci.assets._ALL_PlayAnimationFromName("UseAnimationAction", false)
    end
end
en/vci/sample/onuse/no3.txt · Last modified: 2023/05/11 19:58 by pastatto

Page Tools