代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。

原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html



九.主角可夜视(按键盘H键开关夜视功能)

	用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/player_common.lua文件,在inst:AddComponent("playeractionpicker")的下一行插入以下内容:

local function lightson(inst)
	inst.components.machine.ison = true
	inst.Light:Enable(true)
end
local function lightsoff(inst)
	inst.components.machine.ison = false
	inst.Light:Enable(false)
end
	local light = inst.entity:AddLight()
	light:SetFalloff(1)
	light:SetIntensity(.8)
	light:SetRadius(10)
	light:Enable(false)
	light:SetColour(0/255, 255/255, 0/255)
	inst:AddComponent("machine")
	inst.components.machine.turnonfn = lightson
	inst.components.machine.turnofffn = lightsoff
TheInput:AddKeyUpHandler(KEY_H, function() if inst.components.machine:IsOn() then inst.components.machine:TurnOff() else inst.components.machine:TurnOn() end end )

	即可在游戏中按键盘H键开关主角夜视功能,不再需要火炬、矿工灯