local mainCamera local player local isRequiredActionComplete = false local isActive local public lootTableNum = "3" local public interactionType = "" local textType function Start() player = TransformEx.MyPlayerTransform() isActive = true --Creates customized vfx for the object loadAsync("Packages/Effect/JMOAssets/CFX4_Aura_Bubble_C",OnLoadEffects) --After receiving the reward, enter the cooldown time. When the cooldown time is over, you will receive this message notification, luaEvent:AddEventListener("woogi-event-rewardReset-"..transform:GetInstanceID(),this,OnReset) --When the scene is loaded, a message notifies whether the reward is available (of course, it will only be received using global data) luaEvent:AddEventListener("woogi-event-rewardOnLoad-"..transform:GetInstanceID(),this,OnRewardLoad) CS.Extend.RegisterReward(transform,"3",2,false,false) -- 1. apply lootable to this object, 2. use loot table 3, 3. individual player lootable cooldown, 4. enable vfx when reward available, 5. do not allow "c" interact --Toast message information and register local Platformtext = CS.GMS.WPlatform.webGLPlatform == CS.WoogiWorld.WebGLPlatform.ios and "Touch the green " or "Press " Platformtext = Platformtext .. "F to Find Out What This Is" CS.Extend.RegisterToastMsg(transform,Platformtext,OnPressF,"f",3) end function OnReset() print("重置-----------",transform.name) --gameObject:SetActive(true)--the cooldown time is over,reward is available loadAsync("Packages/Effect/JMOAssets/CFX4_Aura_Bubble_C",OnLoadEffects) end local bl --Returns bool value based on reward status function OnRewardLoad(info) if info:CheckData() then bl=info.Data print(bl, "is the reward return variable") if bl == false then DestroyFX() end end end --Adds vfx to gameObject local fxs function OnLoadEffects(obj) if obj~=nil then goTransfer = newObject(obj) local _tf = goTransfer.transform _tf:SetParent(gameObject.transform) _tf.localPosition= Vector3.zero _tf.localScale = Vector3.one _tf.localEulerAngles = Vector3.zero fxs = _tf.gameObject end if fxs ~= nil then CanBeSeen() end end --Adds vfx when in range function AddFx() if fxs ~= nil then fxs:SetActive(true) isActive = true end end --Removes vfx when out of range function RemoveFx() if fxs ~= nil then fxs:SetActive(false) isActive = false end end --Removes vfx when reward unavailable function DestroyFX() print("Destroy func called") if fxs ~= nil then GameObject.Destroy(fxs) fxs = nil end end --Check player distance from object to prevent extra vfx function CanBeSeen() if (gameObject.transform.position - player.position).sqrMagnitude < 150 then if fxs ~= nil and isActive == false then AddFx() end else if fxs ~= nil and isActive then RemoveFx() end end transform:Invoke(CanBeSeen, 1.5) end --Fkey interaction function OnPressF() -- OnDisableInteraction() textType = interactionType CS.GameManager.PlayerMovement(false) --Give gift to player if available local r = gameObject:GetComponent("RandomReward") if r~=nil then r:GetGift() if fxs ~= nil then DestroyFX() end end DispatchText() transform:Invoke(ResetUse,5) inUse = true end --Dispatch text info based on interaction object function DispatchText() print (textType, "is the text type") if textType == "MegaPibot" then luaEvent:DispatchEvent('OpenMegaPiBotText') elseif textType == "Arcade" then luaEvent:DispatchEvent('OpenArcadeMachineText') elseif textType == "InfoDec" then luaEvent:DispatchEvent('OpenInfoDecText') elseif textType == "Kinara" then luaEvent:DispatchEvent('OpenKinaraText') elseif textType == "Holi" then luaEvent:DispatchEvent('OpenHoliText') elseif textType == "Pibot" then luaEvent:DispatchEvent('OpenPiBotText') elseif textType == "Dreidel" then luaEvent:DispatchEvent('OpenDriedelText') elseif textType == "Input" then luaEvent:DispatchEvent('OnEnableInputUI') elseif textType == "Boombot" then luaEvent:DispatchEvent('OpenBoomBotText') end end --Reset toast message interaction function ResetUse() inUse = false end --Remove toast message and UI objects on interact end function OnDisableInteraction() luaEvent:RemoveEventListener('keyboard.F',this) CS.Extend.CloseToastMsg() CS.Extend.UnregisterToastMsg(transform) end