道具百科
触发器百科
脚本API百科
创作手册
创作功能
其他
Studio百科
综合案例:可以看时间的闹钟
彼得兔 更新时间: 2022-08-18 18:12:23

 

游戏内的效果:

原理:使用Actor:setFacePitch(...)接口可以设置生物的仰角,找好合适的位置,用指针做脑袋、钟面做身体,即可视线钟表效果。

 

教程:

第一步,制作钟面、指针的微缩模型

 

第二步,使用生物模型方块里的“人物”或“四肢动物”拼装闹钟生物模型,钟面做身体,指针做脑袋,其余部位用小方块微缩藏在下面;指针和钟面的位置可能需要实验调整:

 

第三步,在自定义生物插件制作闹钟生物

 

第四步,在脚本编辑器上方ID库查询闹钟生物id:

 

第五步,复制以下脚本到游戏,转成玩法放置闹钟生物蛋测试

local clockid,turnid=11,12054--闹钟生物id,小雪球id
local clocks={}
local function Create(e)
    local objid=e.eventobjid
	local result,actorid=Creature:getActorID(objid)
	if actorid==clockid then
		Actor:setActionAttrState(objid,1,false)
		Actor:setActionAttrState(objid,32,false)
		Actor:setActionAttrState(objid,64,false)
		Actor:setActionAttrState(objid,128,false)
		Actor:setActionAttrState(objid,256,false)
		Creature:setAIActive(objid,false)
		Actor:setFaceYaw(objid,0)
		clocks[#clocks+1]=objid
	end
end
ScriptSupportEvent:registerEvent('Actor.Create',Create)
local function Hour(e)
	local i=0
	for i=1,#clocks do
		Actor:setFacePitch(clocks[i],e.hour%12*30)
	end
end
ScriptSupportEvent:registerEvent('Game.Hour',Hour)
local function ClickActor(e)
	local playerid,objid=e.eventobjid,e.toobjid
	local result,actorid=Creature:getActorID(objid)
	if actorid==clockid then
		local result,timenow=World:getHours()
		Chat:sendSystemMsg("现在是".. timenow .."点")
	end
end
ScriptSupportEvent:registerEvent('Player.ClickActor',ClickActor)
local function Hit(e)
	local itemid,objid=e.itemid,e.toobjid
	if objid~=nil and itemid==turnid then
		local result,actorid=Creature:getActorID(objid)
		if actorid==clockid then
			Actor:turnFaceYaw(objid,45)
		end
	end
end
ScriptSupportEvent:registerEvent('Actor.Projectile.Hit',Hit)

 

转成玩法后,放置闹钟生物蛋,点击闹钟会显示时间,使用雪球击中闹钟可以转向;每到整点,闹钟指针会旋转30度,指向正确的时间:

 

如果使用生物比较麻烦的话,也可以用方块代替,点击报时也是不错的;有耐心可以准备12个闹钟模型,每个模型指向不同的时间,时间到时替换模型。这个就留给小伙伴们自己尝试咯~

站点有内容要更新是否更新。
更新
忽略