Unity光子视图

时间:2019-12-17 13:53:38

标签: unity3d

所以我在网上第一次使用统一游戏使用光子,但是我已经遇到了问题。我的动作脚本很好用,同步效果很好。等等。但是,当我尝试执行固定在播放器上的摄像头时,跟随它,但是第二个播放器看起来像他在移动(但是变换位置没有移动) )。 这是我的PlayerInitializer脚本,我用来生成播放器并连接相机:

using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
public class PlayerInitializer : MonoBehaviour
{
    // Start is called before the first frame update
    public Camera mainCamera;
    void Start()
    {
        StartCoroutine(CreatePlayer());
    }

    IEnumerator CreatePlayer()
    {
        Debug.Log("Creation du joueur");
        GameObject MyPlayer = PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs", "PhotonPlayer"), Vector3.zero, Quaternion.identity) as GameObject;
        mainCamera.GetComponent<Following_Camera>().player = MyPlayer.transform;
        yield return new WaitForSeconds(1);
    }
}

这是PlayerMovement脚本(基本脚本):

using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class PlayerMovement : MonoBehaviour
{
    public float moveSpeed = 5f;
    public Rigidbody2D rb;
    public Animator animator;
    Vector2 movement;
    PhotonView view;
    private void Start()
    {
        view = GetComponent<PhotonView>();
    }
    private void Update()
    {
        movement.x = Input.GetAxisRaw("Horizontal");
        movement.y = Input.GetAxisRaw("Vertical");

        animator.SetFloat("Horizontal", movement.x);
        animator.SetFloat("Vertical", movement.y);
        animator.SetFloat("Speed", movement.sqrMagnitude);
    }
    void FixedUpdate()
    {
        if (view.IsMine)
        {
            rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
        }
    }
}

然后是我的相机脚本:

using UnityEngine;
using System.Collections;

public class Following_Camera : MonoBehaviour
{
    public Transform player;
    private Vector3 offset;

    void Start()
    {
        offset = new Vector3(0,0,-10);

    }

    void LateUpdate()
    {
        transform.position = player.transform.position + offset ;
    }
}

Video of the problem

2 个答案:

答案 0 :(得分:-1)

Z可能会更改

  player.transform.position

也许

transform.position = new Vector3 (player.transform.position.x, player.transform.position.y, -10)

足以使相机停止绕转

答案 1 :(得分:-1)

好的,所以如果有人遇到相同的问题,请注意您是否在3D对象上进行测试。问题是我使用的是3D字体框,因此2D运动就像我在看着他旁边的另一个精灵一样。这就是为什么变换不变但视图不变的原因。

相关问题