728x90
์์ ๊ธ๊ณผ ์ด์ด์ ์์ฑํ๋ ๊ฒ์ ๋๋ค.
Transform View ์ปดํฌ๋ํธ๋ฅผ ๋นผ๋ ์ ์๋ํ๋ ์ฝ๋ + ์ฃผ์
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
//๊ด์ธก ์ปจํธ๋กค๋ฌ
//์ํ๋ณํ ๊ด์ธก(๋ฐ์ดํฐ์ ์ฃผ๊ณ ๋ฐ์)
public class playerController : MonoBehaviourPunCallbacks, IPunObservable
{
private Vector3 curPos;
private Quaternion curRot;
void Start()
{
}
void Update()
{
if(photonView.IsMine)//๋ด๊ฐ ํด๋ผ์ด์ธํธ์ผ๋
{
//ํ์์ ๊ตฌํํ๋ ํ๋ ์ด์ด ๋ก์ง์ ์ฌ๊ธฐ์๋ค๊ฐ ๊ตฌํํ๋ฉด ๋๋ค.
float v = Input.GetAxis("Vertical");
float h = Input.GetAxis("Horizontal");
Vector3 moveDir = (Vector3.forward * v) + (Vector3.right * h);
transform.Translate(moveDir*Time.deltaTime*10f);
}
else//๋ด๊ฐ ๋ณด๊ณ ์๋ ๋ค๋ฅธ ํ๋ ์ด์ด
{
//OnPhotonSerializeView()์ else์ ์๋ ๋ด์ฉ์ ๋ฃ์ด์ค๋ค
transform.position = Vector3.Lerp(transform.position,curPos,Time.deltaTime*10f); //(1)๋ฃ์ด์ค
transform.rotation = Quaternion.Lerp(transform.rotation,curRot,Time.deltaTime*10f); //(2) ๋ฃ์ด์ค
}
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if(stream.IsWriting)//์ฐ๋ ์ํ, ์๋๋ฐฉ์๊ฒ ๋์ ์ ๋ณด๋ฅผ ๋ณด๋(์ ๋๋ฉ์ด์
, ์๊น ๋ณํ.. ๋ฑ๋ฑ)
{//๋ณด๋ด๊ธฐ
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}//๋ฐ๊ธฐ
else//๋ณด๋ธ๊ฑธ ๋๊ฐ์ด ์์๋๋ก ๋ฐ์
{
curPos = (Vector3)stream.ReceiveNext(); //(1)
curRot = (Quaternion)stream.ReceiveNext(); //(2)
}
}
}
728x90