This article was written for “UniVCI-0.15.”
To execute a process when a Collider (Trigger) collides with a SubItem, use “onTriggerEnter”.
To execute a process when a Collider (Trigger) disengages, use “onTriggerExit”.
1. Create a new GameObject and create a Cube, a Sphere and a Plane as its child.
In this example, we named the GameObject “TriggerEnterExit_VCI,” but it can be anything really.
Configure the objects as below:
2. To change the color of the Cube, create a new material file “TriggerMaterial”. Set the created TriggerMaterial as the material of the Cube.
3. Attach a “VCI Object” component on the GameObject,
and attach the “VCI SubItem” component on the Cube, Ball and Plane.
When doing this, “RigidBody” components are also attached automatically.
As the Cube and the Plane won't be using gravity, turn off Use Gravity and turn on Is Kinematic.
As we need the Ball to have physics, turn on Use Gravity and turn off 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.
local green = Color.__new(0,1,0,0.5) local red = Color.__new(1,0,0,0.5) function onTriggerEnter(item, hit) if item == "Ball" and hit == "Cube" then vci.assets._ALL_SetMaterialColorFromName("TriggerMaterial", red) end end function onTriggerExit(item, hit) if item == "Ball" and hit == "Cube" then vci.assets._ALL_SetMaterialColorFromName("TriggerMaterial", green) end end