Hi I'm trying photon multiplayer movement for the first time, there seems to be issue when I move my player the other connected person sees the player which I'm moving & not theirs. Below is the code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class Player_Movement : MonoBehaviour
{
[SerializeField] float speed;
[SerializeField] float xDirection;
[SerializeField] float zDirection;
[SerializeField] Vector3 moveDirection;
private PhotonView view;
private void Start()
{
view = GetComponent<PhotonView>();
}
void Update()
{
if (view.IsMine)
{
xDirection = Input.GetAxis("Horizontal");
zDirection = Input.GetAxis("Vertical");
moveDirection = new Vector3(xDirection, 0.0f, zDirection);
transform.position += moveDirection * speed * Time.deltaTime;
}
}
}
I have made camera component as child of the player.
IEnumerator Start()
{
yield return new WaitUntil(() => PhotonNetwork.IsConnectedAndReady);
Vector3 playerPos = new Vector3(Random.Range(xMin, xMax), 0.0f, Random.Range(zMin, zMax));
GameObject obj = PhotonNetwork.Instantiate(playerPrefab.name, playerPos, Quaternion.identity);
cameraObject = GameObject.Find("Camera").GetComponent<Camera>().gameObject;
cameraObject.transform.parent = obj.transform;
obj.SetActive(true);
}
First you have to create photon rooms. If you created and joined photon room then you have to create players like codes below
"Character/A" is your character prefab url. This character must be in the Resource folder and also have Photon Transform View component. I hope it will work for your project.