Photon Player Mover Failure
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerNetworkMover : Photon.MonoBehaviour {
Vector3 realPosition;
Quaternion realRotation;
float smoothing = 10f;
void Start () {
if (photonView.isMine)
{
GetComponent<MeshRenderer>().material.SetColor("_Color", Color.red);
GetComponent<KarakterKontrol>().enabled = true;
GetComponentInChildren<Weapon>().enabled = true;
GetComponentInChildren<WeaponSway>().enabled = true;
foreach (Camera cam in GetComponentsInChildren<Camera>())
cam.enabled = true;
transform.Find("MainCamera/GunCamera/Ak-47/ak").gameObject.layer = 9;
}
else
{
StartCoroutine("UpdateDate");
}
}
IEnumerator UpdateDate()
{
while (true)
{
transform.position = Vector3.Lerp(transform.position, realPosition, Time.deltaTime * smoothing);
transform.rotation = Quaternion.Lerp(transform.rotation, realRotation, Time.deltaTime * smoothing);
}
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else
{
realPosition = (Vector3)stream.ReceiveNext();
realRotation = (Quaternion)stream.ReceiveNext();
}
}
void Update () {
}
}
Hello friends. I am playing a game but when I write the game I wrote the code for the player mover. But when the code runs the code does not work sometimes, but the character moves are shifting, or the gun does not appear, or only one looks. The player's characters seem to be shifting. Friends please help me?
And i got a script from the asset store i bought photon matchmaking v2 i am trying to make a game with it but the photon player network mover is not working please help.
And i got a script from the asset store i bought photon matchmaking v2 i am trying to make a game with it but the photon player network mover is not working please help.
Hi,
you don't need to start a Coroutine, you can handle this also in the Update function by using the is$$anonymous$$ine condition of the PhotonView component. Please try this and tell us if this works. Besides that I currently don't see any other issues.
I tried it but it did not. Same error again. what else can I do
this Character Controller;
public float hareketHizi;
public float ziplama;
public GameObject kamera;
public GameObject kapsul;
public float kameraAcisi;
void Start () {
}
void Update () {
$$anonymous$$arakterHareket();
$$anonymous$$amera$$anonymous$$ontrol();
}
void $$anonymous$$amera$$anonymous$$ontrol()
{
float x = Input.GetAxis("$$anonymous$$ouse X");
float y = Input.GetAxis("$$anonymous$$ouse Y");
kapsul.transform.Rotate(new Vector3(0, 1, 0) * x);
kameraAcisi -= y;
kameraAcisi = $$anonymous$$athf.Clamp(kameraAcisi, -90, 90);
kamera.transform.localEulerAngles = new Vector3(kameraAcisi, 0, 0);
}
void $$anonymous$$arakterHareket()
{
float v = Input.GetAxis("Vertical");
float h = Input.GetAxis("Horizontal");
Vector3 yon = Vector3.Normalize(new Vector3(h, 0, v));
transform.Translate(yon * hareketHizi * Time.deltaTime);
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.LeftShift))
{
hareketHizi = 8;
}
if (Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.LeftShift))
{
hareketHizi = 5;
}
RaycastHit ray;
Physics.Raycast(transform.position, Vector3.down, out ray, $$anonymous$$athf.Infinity);
if(ray.distance < 1.2f)
{
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space))
{
GetComponent<Rigidbody>().AddForce(Vector3.up * ziplama);
}
}
}
if there isn't a problem I want to you to send my game files. I made some mistakes. Can you fix that please?
16 days I'm working with this error. But it is not please help
Answer by tatto123321 · Jul 17, 2017 at 09:05 AM
public static MaxPlayers m_InstanceMax = null; public static ModParty m_InstanceMod = null; public GameObject Room; public Transform[] spawnPoints;
public GameObject myPlayer;
[HideInInspector]
public bool connect = false;
[HideInInspector]
public int ModParty;
private byte Version = 1;
public int PlayerMax = 10;
/// <summary>if we don't want to connect in Start(), we have to "remember" if we called ConnectUsingSettings()</summary>
private bool ConnectInUpdate = true;
private bool Roomcreate = true;
void Awake()
{
DontDestroyOnLoad(gameObject.transform);
}
void Start()
{
PhotonNetwork.autoJoinLobby = false; // we join randomly. always. no need to join a lobby to get the list of rooms.
SceneManager.sceneLoaded += (scene, loadscene) =>
{
if (SceneManager.GetActiveScene().name == "Game")
{
Spawn();
}
};
}
public void Spawn()
{
int index = UnityEngine.Random.Range(0, spawnPoints.Length);
myPlayer = PhotonNetwork.Instantiate("Player", spawnPoints[index].position, spawnPoints[index].rotation, 0);
myPlayer.transform.Find("MainCamera").gameObject.SetActive(true);
((MonoBehaviour)myPlayer.GetComponent("KarakterKontrol")).enabled = true;
}
public virtual void Update()
{
if (ConnectInUpdate && connect && !PhotonNetwork.connected)
{
Debug.Log("Update() was called by Unity. Scene is loaded. Let's connect to the Photon Master Server. Calling: PhotonNetwork.ConnectUsingSettings();");
ConnectInUpdate = false;
PhotonNetwork.ConnectUsingSettings(Version + "." + SceneManagerHelper.ActiveSceneBuildIndex);
}
}
// below, we implement some callbacks of PUN
// you can find PUN's callbacks in the class PunBehaviour or in enum PhotonNetworkingMessage
public virtual void OnConnectedToMaster()
{
Debug.Log("Cherche party en mode : "+ModParty);
ExitGames.Client.Photon.Hashtable expectedProperties = new ExitGames.Client.Photon.Hashtable();
expectedProperties.Add( RoomProperty.Type, ModParty.ToString());
PhotonNetwork.JoinRandomRoom( expectedProperties, 0 );
}
public virtual void OnPhotonRandomJoinFailed()
{
Debug.Log("Aucune party, on en crée une.");
RoomOptions roomOptions = new RoomOptions();
roomOptions.maxPlayers = (byte)PlayerMax;
roomOptions.customRoomProperties = new ExitGames.Client.Photon.Hashtable();
roomOptions.customRoomProperties.Add( RoomProperty.Map, "Test" );
roomOptions.customRoomProperties.Add( RoomProperty.Type, ModParty.ToString() );
roomOptions.customRoomPropertiesForLobby = new string[] {
RoomProperty.Map,
RoomProperty.Type,
};
PhotonNetwork.CreateRoom ("TestMap" + "@" + Guid.NewGuid().ToString("N"), roomOptions, null);
Roomcreate = true;
}
public void OnJoinedRoom()
{
Debug.Log("In Room");
AutoFade.m_Instance.BeginFade (-1);
Room.SetActive (true);
Room.GetComponent<ManageListMembers> ().PlayerMax = PlayerMax;
this.gameObject.SetActive (false);
PhotonNetwork.playerName = ClickMenuMain.m_InstancePseudo.pseudo;
m_InstanceMax = (new GameObject("maxplayers")).AddComponent<MaxPlayers>();
m_InstanceMod = (new GameObject("modparty")).AddComponent<ModParty>();
m_InstanceMax.maxplayers = PlayerMax;
m_InstanceMod.modparty = ModParty;
}
and this photon network manager script;