add range indicator when placing towers
This commit is contained in:
1 parent
4e29ad0824
commit
a7ce7f9796
1 file changed
+54
-1
+54
-1
@@ -1,4 +1,6 @@
|
|||||||
local RunService = game:GetService("RunService")
|
local RunService = game:GetService("RunService")
|
||||||
|
local UserInputService = game:GetService("UserInputService")
|
||||||
|
|
||||||
local Tower = require(script.Parent.Tower)
|
local Tower = require(script.Parent.Tower)
|
||||||
local Waves = require(script.Parent.Waves)
|
local Waves = require(script.Parent.Waves)
|
||||||
|
|
||||||
@@ -46,6 +48,8 @@ local waypoints = { -- Fill with your waypoint Parts
|
|||||||
local selectedTowerType = towerTypes[1]
|
local selectedTowerType = towerTypes[1]
|
||||||
local enemies = {} -- Table to hold TrackEnemy objects
|
local enemies = {} -- Table to hold TrackEnemy objects
|
||||||
local towers = {}
|
local towers = {}
|
||||||
|
local placingTower = false
|
||||||
|
local rangeIndicator = nil
|
||||||
|
|
||||||
function selectTowerType(index)
|
function selectTowerType(index)
|
||||||
selectedTowerType = towerTypes[index]
|
selectedTowerType = towerTypes[index]
|
||||||
@@ -79,9 +83,57 @@ local function isOnTrack(position)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function showRangeIndicator(position, range)
|
||||||
|
if not rangeIndicator then
|
||||||
|
rangeIndicator = Instance.new("Part")
|
||||||
|
rangeIndicator.Name = "RangeIndicator"
|
||||||
|
rangeIndicator.Shape = Enum.PartType.Cylinder
|
||||||
|
rangeIndicator.Anchored = true
|
||||||
|
rangeIndicator.CanCollide = false
|
||||||
|
rangeIndicator.Transparency = 0.6
|
||||||
|
rangeIndicator.Color = Color3.fromRGB(100, 200, 255)
|
||||||
|
rangeIndicator.Material = Enum.Material.Neon
|
||||||
|
rangeIndicator.Size = Vector3.new(range * 2, 0.2, range * 2)
|
||||||
|
rangeIndicator.Parent = workspace
|
||||||
|
-- Rotate so cylinder is flat
|
||||||
|
rangeIndicator.Orientation = Vector3.new(0, 0, 90)
|
||||||
|
end
|
||||||
|
rangeIndicator.Size = Vector3.new(range * 2, 0.2, range * 2)
|
||||||
|
rangeIndicator.Position = Vector3.new(position.X, position.Y + 0.1, position.Z)
|
||||||
|
rangeIndicator.Visible = true
|
||||||
|
end
|
||||||
|
|
||||||
|
local function hideRangeIndicator()
|
||||||
|
if rangeIndicator then
|
||||||
|
rangeIndicator:Destroy()
|
||||||
|
rangeIndicator = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
RunService.RenderStepped:Connect(function ()
|
||||||
|
if placingTower then
|
||||||
|
local mouse = game.Players.LocalPlayer:GetMouse()
|
||||||
|
local position = mouse.Hit.p
|
||||||
|
showRangeIndicator(position, selectedTowerType.range)
|
||||||
|
else
|
||||||
|
hideRangeIndicator()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
UserInputService.InputBegan:Connect(function(input, gameProcessed)
|
||||||
|
if gameProcessed then return end
|
||||||
|
if input.KeyCode == Enum.KeyCode.T then
|
||||||
|
placingTower = not placingTower
|
||||||
|
print("Tower Placing Mode:", placingTower and "ON" or "OFF")
|
||||||
|
if not placingTower then
|
||||||
|
hideRangeIndicator()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
UserInputService.InputBegan:Connect(function (input, gameProcessed)
|
UserInputService.InputBegan:Connect(function (input, gameProcessed)
|
||||||
if gameProcessed then return end
|
if gameProcessed then return end
|
||||||
if input.UserInputType == Enum.UserInputType.MouseButton1 then
|
if input.UserInputType == Enum.UserInputType.MouseButton1 and placingTower then
|
||||||
local mouse = game.Players.LocalPlayer():GetMouse()
|
local mouse = game.Players.LocalPlayer():GetMouse()
|
||||||
local position = mouse.Hit.p
|
local position = mouse.Hit.p
|
||||||
if not isOnTrack(position) then
|
if not isOnTrack(position) then
|
||||||
@@ -94,6 +146,7 @@ UserInputService.InputBegan:Connect(function (input, gameProcessed)
|
|||||||
selectedTowerType.effect
|
selectedTowerType.effect
|
||||||
)
|
)
|
||||||
table.insert(towers, tower)
|
table.insert(towers, tower)
|
||||||
|
hideRangeIndicator()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in new issue
Block a user