Menu
CoddyTech

ゾンビを出現させる

Coddyの「Robloxゲーム:タワーディフェンス」コースのレッスン 2/22。

敵はworkspace.Path.Waypoints内にある、1から6という名前の見えないパーツで示された道を歩きます。GetChildrenは順序を保証しないため、まず名前に含まれる数字で並べ替えます。

local points = workspace.Path.Waypoints:GetChildren()
table.sort(points, function(a, b)
	return tonumber(a.Name) < tonumber(b.Name)
end)

各敵はServerStorage.Enemies内のモデルです。モデルを複製し、PivotToでモデル全体を移動させてから、ワークスペースに親として設定すると表示されます。

local runner = ServerStorage.Enemies.Runner:Clone()
runner:PivotTo(points[3].CFrame + Vector3.new(0, 4, 0))
runner.Parent = workspace.Enemies
challenge icon

チャレンジ

簡単

経路の開始地点にゾンビを出現させましょう。

  1. 上部付近に、local ServerStorage = game:GetService("ServerStorage") と local enemies = workspace.Enemies を記述します。
  2. workspace.Path.Waypoints:GetChildren() を tonumber(a.Name) で並べ替え、waypoints に格納します。
  3. spawnEnemy(kind) を記述します。ServerStorage.Enemies[kind] を複製し、PivotTo で waypoints[1] の5スタッド上に移動させ、親を enemies に設定し、それを返します。spawnEnemy("Zombie") を呼び出します。

「プレイ」を押すと、経路の開始地点にゾンビが出現します。その後、「確認」を押します。

自分で試してみよう

local Players = game:GetService("Players")
local Settings = require(game.ReplicatedStorage.Settings)

print("The base can take " .. Settings.BaseHealth .. " hits")

-- すべてのプレイヤーのリーダーボードに Money が追加される
Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local money = Instance.new("IntValue")
	money.Name = "Money"
	money.Value = Settings.StartMoney
	money.Parent = leaderstats
end)

-- Lesson 2: Spawn a Zombie をここに記述する

Robloxゲーム:タワーディフェンスのすべてのレッスン

自分で練習してみよう: Robloxプレイグラウンド