Lua Script Roblox Studio: การประกาศและเรียกใช้ Function 

สร้าง Function เพื่อหาวัตถุที่อยู่ใกล้สุด




local parts = {Vector3.new(5, 3, 4), Vector3.new(1, 2, 5), Vector3.new(-7, 0, 9)} -- Add more part here

Function FindNearestPart(me, others)

local nearestDistance = math.huge -- Start with large number
local nearestPart = nil -- nil is empty for object's reference

for _, part in others do -- For each loop for table

if (part - me).Magnitude < nearestDistance then

nearestDistance = (part - me).Magnitude
nearestPart = part

end -- end if

end -- end loop

return nearestPart -- return result

end

print(FindNearestPart(Vector3.new(0, 0, 0), parts))

ไม่มีความคิดเห็น:

แสดงความคิดเห็น

ผ้าคลุมล่องหน หรือ The Large Frabic of Time

 ตอนเด็กๆผมเคยเห็นปกสมุดวาดรูปเป็นเทพวีนัสที่แขนหายไป เอ มีรูปแกะสลักที่ชิ้นส่วนไม่ครบอยู่หลายที่ในโลกนะ จะบอกว่าโจรขโมยบางส่วน สู้ขโมยทั้งห...