====== Color and animation switching light ====== === Example data === https://virtualcast.jp/products/8ff27fbabc1414b88b29beae1c431720bb48e96e3aaa0c88a0082760dccd0665 === UnityPackage === {{ vci:sample:sample_advanced:tutorial_light.zip |}} It's a light which you can change the color and the shape of.\\ The state of the light is synchronized between users by sharing the state of the color and the shape using sync variables.\\ It plays scaling animation of the light when the black lamp shade is being onUsed.\\ When the white part at the back of the light is onUsed, the color of the light will change. {{vci:sample:sample_advanced:tutorial_light_1.png?400|}} local state=0 --0Short 1Long local color_state=0 --0 White   Others: the state of color. local to_color = Color.__new(1,0,0,1)--Color of preference function onUse(use) --Synchronization-------------------------------- if vci.state.Get("STATE")==nil then--Synchronization of the state vci.state.Set("STATE",state) else state=vci.state.Get("STATE")--Get the state from the sync variable when gripped end if vci.state.Get("STATE")==nil then--Synchronization of the light_state vci.state.Set("COLOR_STATE",color_state) else state=vci.state.Get("STATE")--Get the state from the sync variable when gripped end --State of the light------Executed when the base part is gripped--------------- if use=="light_forstage" then print("base_grab_OK")--------------- if state==0 then vci.assets._ALL_PlayAnimationFromName("light_long",false) state=1 vci.state.Set("STATE",state) elseif state==1 then vci.assets._ALL_PlayAnimationFromName("light_short",false) state=0 vci.state.Set("STATE",state) end end --Executed when the lampshade is gripped------------------------- if use=="light_controller" then color_state=color_state+1 print("light_grab_OK")--------------- if color_state>7 then color_state=0--to the prefered color end vci.state.Set("COLOR_STATE",color_state)--同期 if color_state==0 then to_color = Color.__new(1,1,1,0.2)--The prefered color vci.assets._ALL_SetMaterialColorFromName ("light_light",to_color) vci.assets._ALL_SetMaterialColorFromName ("light_noshadow",to_color) elseif color_state==1 then to_color = Color.__new(1,0,0,0.2)--red vci.assets._ALL_SetMaterialColorFromName ("light_light",to_color) vci.assets._ALL_SetMaterialColorFromName ("light_noshadow",to_color) elseif color_state==2 then to_color = Color.__new(1,0.65,0,0.2)--orange vci.assets._ALL_SetMaterialColorFromName ("light_light",to_color) vci.assets._ALL_SetMaterialColorFromName ("light_noshadow",to_color) elseif color_state==3 then to_color = Color.__new(1,1,0,0.2)--yellow vci.assets._ALL_SetMaterialColorFromName ("light_light",to_color) vci.assets._ALL_SetMaterialColorFromName ("light_noshadow",to_color) elseif color_state==4 then to_color = Color.__new(0,0.5,0,0.2)--green vci.assets._ALL_SetMaterialColorFromName ("light_light",to_color) vci.assets._ALL_SetMaterialColorFromName ("light_noshadow",to_color) elseif color_state==5 then to_color = Color.__new(0,1,1,0.2)--blue vci.assets._ALL_SetMaterialColorFromName ("light_light",to_color) vci.assets._ALL_SetMaterialColorFromName ("light_noshadow",to_color) elseif color_state==6 then to_color = Color.__new(0,0,1,0.2)--indigo vci.assets._ALL_SetMaterialColorFromName ("light_light",to_color) vci.assets._ALL_SetMaterialColorFromName ("light_noshadow",to_color) elseif color_state==7 then to_color = Color.__new(0.5,0,0.5,0.2)--violet vci.assets._ALL_SetMaterialColorFromName ("light_light",to_color) vci.assets._ALL_SetMaterialColorFromName ("light_noshadow",to_color) else ---- Do nothing end end----------- end