代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。
原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html
1
2一0九.主角可夜视(按键盘H键开关夜视功能)
3
4 用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/player_common.lua文件,在inst:AddComponent("playeractionpicker")的下一行插入以下内容:
5
6local function lightson(inst)
7 inst.components.machine.ison = true
8 inst.Light:Enable(true)
9end
10local function lightsoff(inst)
11 inst.components.machine.ison = false
12 inst.Light:Enable(false)
13end
14 local light = inst.entity:AddLight()
15 light:SetFalloff(1)
16 light:SetIntensity(.8)
17 light:SetRadius(10)
18 light:Enable(false)
19 light:SetColour(0/255, 255/255, 0/255)
20 inst:AddComponent("machine")
21 inst.components.machine.turnonfn = lightson
22 inst.components.machine.turnofffn = lightsoff
23TheInput:AddKeyUpHandler(KEY_H, function() if inst.components.machine:IsOn() then inst.components.machine:TurnOff() else inst.components.machine:TurnOn() end end )
24
25 即可在游戏中按键盘H键开关主角夜视功能,不再需要火炬、矿工灯