I am creating a multiplayer service using photon. It is possible for the user to move using WASD or Joystick in this service. The joystick function works well when I am alone, but when someone else enters, the joystick function for everyone does not work. How can I fix this?
This is the inspector setting for select a character.
This is the code for selecting a character.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Photon.Pun;
public class SimpleLauncher : MonoBehaviourPunCallbacks
{
public PhotonView playerPrefab;
public InputField playerNickname;
public GameObject nicknameInput;
public string chooseAvatar = "User1";
public override void OnConnectedToMaster()
{
Debug.Log("Connected to Master");
PhotonNetwork.JoinRandomOrCreateRoom();
}
public override void OnJoinedRoom()
{
Debug.Log("Joined a room.");
PhotonNetwork.Instantiate(playerPrefab.name, Vector3.zero, Quaternion.identity);
}
public void StartTheGame()
{
PhotonNetwork.NickName = playerNickname.text + "-" + chooseAvatar;
PhotonNetwork.ConnectUsingSettings();
nicknameInput.SetActive(false);
}
public void SetAvater(string avatarName)
{
chooseAvatar = avatarName;
}
}
This is the inspector setting for Player
This is the inspector setting for Player
This is Player Scripts
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Photon.Pun;
public class SimplePlayer : MonoBehaviourPunCallbacks
{
public float speed = 1f;
public float rspeed = 5f;
float currentVeclocity;
float currentSpeed;
float speedVelocity;
public float MoveSpeed = 1f;
public float smoothRotationTime = 0.25f;
public bool enableMobileInputs = false;
public FixedJoystick joystick;
void Start()
{
GameObject chooseAvatar = (GameObject)Instantiate(Resources.Load(photonView.Owner.NickName.Split('-')[1]));
chooseAvatar.transform.SetParent(transform);
}
void Update()
{
if (!photonView.IsMine)
{
return;
}
Vector3 input = Vector3.zero;
if (enableMobileInputs)
{
input = new Vector3(joystick.input.x, joystick.input.y);
}
else
{
input = new Vector3(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
}
Vector3 inputDir = input.normalized;
if (inputDir != Vector3.zero)
{
float rotation = Mathf.Atan2(inputDir.x, inputDir.y) * Mathf.Rad2Deg;
transform.eulerAngles = Vector3.up * Mathf.SmoothDampAngle(transform.eulerAngles.y, rotation, ref currentVeclocity, smoothRotationTime);
}
float tragetSpeed = MoveSpeed * inputDir.magnitude;
currentSpeed = Mathf.SmoothDamp(currentSpeed, tragetSpeed, ref speedVelocity, 0.1f);
transform.Translate(transform.forward * currentSpeed * Time.deltaTime, Space.World);
}
}
I'm in desperate need of help. Please help me.
I thought it might be a problem with the joystick code at first, so I tried writing a different joystick code. Then, I checked if the IsMine state was not true when someone else entered, but that wasn't the issue either.