RemoteFunction 和 RemoteEvent用来和 客户端和服务器通信;
可以分为3步走:
- 1、创建对象
- 2、客户端 触发对象
- 3、服务器 处理事件
1、创建 RemoteFunction 和 RemoteEvent
建议用 ServerScriptService 里的脚本 创建; 并保存到 ReplicatedService里面
--动态创建 RemoteFunction 和 RemoteEvent
--Service
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- RemoteFunction for when a projectile is launched
--告诉服务器 发射子弹
local launchProjectile = Instance.new("RemoteFunction")
launchProjectile.Name = "LaunchProjectile"
launchProjectile.Parent = ReplicatedStorage
-- REmoteFunction for ping all client
--告诉服务器 pink
local pingChecker = Instance.new("RemoteFunction")
pingChecker.Name = "PingChecker"
pingChecker.Parent = ReplicatedStorage
--RemoteEvent for when client detects an enemy should be destory
local destroyEnemy = Instance.new("RemoteEvent")
destroyEnemy.Name = "DestroyEnemy"
destroyEnemy.Parent = ReplicatedStorage
-- RemoteEvent destroy projectile
local destroyProjectile