概要
方法
LoadAnimation(animation: Animation):AnimationTrack |
活動
AnimationPlayed(animationTrack: AnimationTrack):RBXScriptSignal |
範例程式碼
使用 AnimationController 動畫非玩家物件
local InsertService = game:GetService("InsertService")
-- 載入一個模型以進行演示
local npcModel = InsertService:LoadAsset(516159357):GetChildren()[1]
npcModel.Name = "NPC"
npcModel.PrimaryPart.Anchored = true
npcModel:SetPrimaryPartCFrame(CFrame.new(0, 5, 0))
npcModel.Parent = workspace
-- 用 animationcontroller 取代 humanoid
local humanoid = npcModel:FindFirstChildOfClass("Humanoid")
humanoid:Destroy()
local animationController = Instance.new("AnimationController")
animationController.Parent = npcModel
-- 創建並載入一個動畫
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/asset/?id=507771019" -- Roblox 舞蹈表情
local animationTrack = animationController:LoadAnimation(animation)
-- 播放動畫
animationTrack:Play()API 參考
方法
GetPlayingAnimationTracks
LoadAnimation
活動
AnimationPlayed