作用:与Photon2连接、添加物体
背景:因为大多数为新场景sence,所以这是以新的场景sence,加入人物来演示
给英雄加Component组件:Photon View(服务器是否观察参数,多个客户端都要知道)
如:
1.位置信息组件:把 Transform 拖到 None(Component),自动创建Photon Transform View, 选择要传输的信息
2.+一个None(Component)
3.动画组件:把 Animator 拖到 None(Component),自动创建Photon Animator View:Disabled(不传输)、Discrete(间歇传输)、Continuous(连续传输)
Using Photon.Pun//使用Photon.Pun这个类
Public class PlayerMovement : MonoBehaviourPun//换Photon.Pun的MonoBehaviourPun
{
private void Update()
{
if (!photonView.IsMine && PhotonNetwork.IsConnected);//如果不是本机操作,photonView小写p
return;
上下左右移动的代码
}
}
把英雄预制体Object放入添加到Photon - PhotonUnityNetworking - Resources(资源)
Using Photon.Pun//使用Photon.Pun这个类
Public class PlayerMovement : MonoBehaviourPun//换Photon.Pun的MonoBehaviourPun
{
void Start()
{
PhotonNetwork.Instantiante("player",new Vector(1,1,0),Quaternion.identity,0);
}
}