• 主页

  • 投资

  • IT

    🔥
  • 设计

  • 销售

  • 共151篇

    Unity - 游戏引擎

关闭

返回栏目

关闭

返回Unity - 游戏引擎栏目

48 - 多人在线 - Photon2 Cloud的连接Connect

作者:

贺及楼

成为作者

更新日期:2024-05-10 16:31:17

作用:多人在线服务器

一、创建Photon账号

二、新建应用Application

获得App id
复制App id

三、Asset Store 找到 PUN 2 - Free 导入到素材里

可以取消Demos — 导入
添加App id — Setup Project
Photon - PhotonUnityNetworking - Resources - PhotonServerSettings 是编辑Photon连接的文件

四、PhotonServerSettings设置

App Version 版本为 1
PUN Logging 登录信息为full

五、创建Object空项目

命名为NetworkLauncher
创建C#脚本命名为Launcher 到Object空项目
C#:

C#:代码

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Photon.Pun
  5. Public class Launcher : MonoBehaviourPunCallbacks
  6. {
  7. // Start is called before the first frame update
  8. void Start()
  9. {
  10. PhotonNetwork.ConnectUsingSettings();
  11. }
  12. public override void OnConnectedToMaster()
  13. {
  14. }
  15. }

代码的解释

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Photon.Pun//添加Photon.Pun
  5. Public class Launcher : MonoBehaviourPunCallbacks//MonoBehaviourPunCallbacks是Photon.Pun的一个类
  6. {
  7. // Start is called before the first frame update
  8. void Start()
  9. {
  10. PhotonNetwork.ConnectUsingSettings();//启用Photon连接文件来连接
  11. }
  12. public override void OnConnectedToMaster()//连接成功后做的事情
  13. {
  14. }
  15. }