代码之家  ›  专栏  ›  技术社区  ›  Elnur Ceferli

光子双关2用鼠标改变位置

  •  0
  • Elnur Ceferli  · 技术社区  · 6 年前

    我认为光子和鼠标位置之间存在问题。因为当我试图用键盘改变物体的位置时,它会成功地工作,但当我试图用鼠标改变位置时,它不会在网络上改变。如何在网络上使用鼠标位置更改对象位置?

    public class SpehreControl : MonoBehaviour
    {
        PhotonView PV;
        GameObject sphere1;
        GameObject bt;
        // Start is called before the first frame update
        void Start()
        {
            PV = GetComponent<PhotonView>();
            sphere1 = GameObject.Find("Sphere 1");
            bt = GameObject.Find("BT_1");
        }
    
        // Update is called once per frame
        void Update()
        {
    
                if (Input.GetMouseButton(0) && PV.IsMine)
                {
                PV.RPC("RPC_MoveOnline", RpcTarget.AllBuffered);
                }
    
        }
    
    
    
        [PunRPC]
        void RPC_MoveOnline()
        {
            transform.position = new Vector3(Camera.main.ScreenToWorldPoint(Input.mousePosition).x,
               Camera.main.ScreenToWorldPoint(Input.mousePosition).y, 0);
    
        }
    
    }
    
    0 回复  |  直到 6 年前
        1
  •  1
  •   Edward Brave    6 年前

    我认为RPC函数中存在的问题。 输入鼠标位置

    您可以使用参数来修复此问题:

    ...
       PV.RPC("RPC_MoveOnline", RpcTarget.AllBuffered, Camera.main.ScreenToWorldPoint(Input.mousePosition));
    ...
    [PunRPC]
    void RPC_MoveOnline(Vector3 worldPosition)
    {
        transform.position = new Vector3(worldPosition.x, worldPosition.y, 0);
    }
    

    但这真的不是一个很好的方法。。。

    处理起来容易多了 照片视图 使改变 组件到 观测分量场

    使用此功能,所有本地围棋转换的更改将自动为所有玩家同步! more info here

    推荐文章