首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >按代码更改排行榜团队

按代码更改排行榜团队
EN

Stack Overflow用户
提问于 2015-07-31 02:13:38
回答 1查看 3.2K关注 0票数 1

我需要做一个代码,将改变一个球员的团队。

假设我有红队和蓝队。

现在我想通过代码让一名球员加入蓝队。

我该怎么做呢?

EN

回答 1

Stack Overflow用户

发布于 2015-07-31 03:20:45

Player对象具有属性TeamColor。当此颜色与TeamTeamColor匹配时,则该球员属于该球队。

如果您只是想将Player1的团队更改为Red Team,您可以这样做:

代码语言:javascript
运行
复制
game.Players.Player1.TeamColor = game.Teams["Blue Team"].TeamColor

还要注意的是,TeamColor实际上是一个BrickColor,这意味着您可以硬编码颜色(但如果您更改团队的BrickColor,则需要更改脚本,但是如果您硬编码TeamColor,则可以毫无顾虑地更改团队名称,这是下面的代码所不允许的)。

代码语言:javascript
运行
复制
local TeamRed = Instance.new("Team")
TeamRed.Name = "Team Red"
TeamRed.TeamColor = BrickColor.new("Bright red")
TeamRed.Parent = game:GetService("Teams")

-- Some other script

game.Players.Player1.TeamColor = BrickColor.new("Bright red")

但是,我建议在代码中创建团队,以便在以后使用它们:

代码语言:javascript
运行
复制
local TeamRed = Instance.new("Team")
TeamRed.Name = "Team Red"
TeamRed.TeamColor = BrickColor.new("Bright red")
TeamRed.Parent = game:GetService("Teams")

local TeamBlue = Instance.new("Team")
TeamBlue.Name = "Team Blue"
TeamBlue.TeamColor = BrickColor.new("Bright blue")
TeamBlue.Parent = game:GetService("Teams")

local some_clever_named_variable = true

game.Players.PlayerAdded:connect(function(Player)
    Player.TeamColor = some_clever_named_variable and TeamRed.TeamColor or TeamBlue.TeamColor
    some_clever_named_variable = not some_clever_named_variable
end)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31731128

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档