en:vci:sample:material:colorchange

Table of Contents

Change the color of materials

This example VCI changes the color of a material when the grip button is pressed.

VCI script

main.lua
function onUse(self)
    print("onUse")
    local r = math.random()
    local g = math.random()
    local b = math.random()
    vci.assets._ALL_SetMaterialColorFromIndex(0, Color.__new(r,g,b))
end

math.random() is a pseudo-random number that returns a random value.
They randomly decide the value for red, blue and green to create a color.

About random

main.lua
-- a = 0 ~ 1
a = math.random()
-- b = 1 ~ 100
b = math.random(100)
-- c = 1000 ~ 2000
c = math.random(1000, 2000)

When you specify no argument, it returns a value between or equal to 0 and 1.
When you specify one argument, it returns a value between or equal to 1 and the argument value.
When you specify two arguments, it returns a value between or equal to the first argument and the second argument.

math.random

en/vci/sample/material/colorchange.txt · Last modified: 2021/06/30 14:26 by t-daihisa

Page Tools