如何使用头像昵称功能
设置头像昵称
- 解答:
使用:
GameServer.lua
--@description 游戏开始时服务端的操作function GameServer:OnStart() local playerId1 = Character:GetPlayerBySideAndIndex(0,1)--获取玩家一ID local playerId2 = Character:GetPlayerBySideAndIndex(0,2)--获取玩家二ID Chat:SetCustomChatName(playerId1, "女巫")--设置玩家一昵称为"女巫" Chat:SetCustomChatName(playerId2, "狼人")--设置玩家二昵称为"狼人" Chat:SetCustomHeadIcon(playerId1, 60030021)--设置玩家一头像为"女巫标识" Chat:SetCustomHeadIcon(playerId2, 60030022)--设置玩家二头像为"狼人标识"end试玩后可在文本聊天中看到玩家的头像及昵称均已更改。
聊天界面:
文本聊天功能控件:
如何使用头像昵称控件
- 解答:
![]() | (1) 先在界面编辑中【功能】-【社交】中找到【头像昵称控件】,然后拖入画布中。 |
|---|---|
![]() | (2) 选中拖出的控件,点击【编辑】,在详情页中找到实例信息一栏中可以看到其中有一个实例ID,点击最后的”复制”按钮可一键复制该ID。 |
使用:
GameClient.lua
--@description 游戏开始时客户端的操作function GameClient:OnStart() --游戏开始时立即使用SetPlayerIconAndNameAPI无效,需延迟1帧执行 TimerManager:AddFrame( 1, function() local playerId = Character:GetLocalPlayerId()--获取客户端本地玩家 UI:SetPlayerIconAndName({ItemUID},playerId,UI.AvatarType.Both) -- 根据玩家设置头像昵称控件,替换ItemUID为头像昵称控件的实例ID end )
