在Unity中使用Photon与玩家不同步
我最近开始使用Photon创建多人游戏游戏,我的教程在此处链接:。正如您可以从此问题的标题中读取的那样,玩家的动作不是同步。
在这里,如果我的播放器代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using Photon.Pun;
public class playerControls : MonoBehaviour
{
[SerializeField] private Rigidbody2D body;
[SerializeField] public Transform bodyTransform;
public float speed;
private float horizontalInput;
public PhotonView view;
// Update is called once per frame
void Update()
{
if(view.IsMine){
if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.D))
{
bodyTransform.localScale = new Vector3(1.3f,1.3f,1.3f);
}
else if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.A))
{
bodyTransform.localScale = new Vector3(-1.3f,1.3f,1.3f);
}
horizontalInput = Input.GetAxis("Horizontal");
body.velocity = new Vector2(horizontalInput * (float)speed, body.velocity.y);
if(Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W)){
body.velocity=new Vector2(body.velocity.x,6);
}
}
}
}
我还使用了光子变换视图,但是它仍然不起作用。
其他一切正常,您可以单独移动每个玩家。您可以加入房间。玩家产卵。但是,唯一的问题是播放器同步不起作用。任何反馈都将得到理解-Jake
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PhotonTransFormView只是可以通过网络同步的组件。您还需要PhotonView将实际同步和拖放到观察到的组件列表中。因此,基本上,PhotonView是网络化的最重要组件,PhotonTransFormView只是来自转换的序列化/进行序列化值。如果添加任何实现ipunobservable的类
PhotonTransformView is just a component that can be synced over the network. You also need PhotonView that does actual sync and drag-and-drop your PhotonTransformView to the Observed Components list. So basically the PhotonView is most important component for networking, PhotonTransformView is just a serializing/deserializing values from transform. If you add any class implementing IPunObservable you need to drag them to the Observed Components list to work