- Home /
Syncing particle system in Photon Unity Networking
When a player clicks left mouse button, they turn invisible and should play a particle that lasts about 1 second. They instantiate the particle in the position where they clicked it. It works for the player who is clicking it. However, other players can't see the particles. I cant find the solution :( help!
private PhotonView PhotonView;
public bool IsStealthed = false;
public AudioSource stealthNoise;
public GameObject stealthParticle;
private void Awake()
{
PhotonView = GetComponent<PhotonView>();
}
private void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
stream.SendNext(IsStealthed);
}
else
{
IsStealthed = (bool)stream.ReceiveNext();
}
}
private void CheckPlayerStealth()
{
IsStealthed = true;
stealthNoise.Play();
GameObject player = PhotonView.Instantiate(stealthParticle, transform.position, transform.rotation);
}
if (!Input.GetMouseButton(0))
{
IsStealthed = false;
}
if (Input.GetMouseButtonUp(0))
{
stealthNoise.Play();
GameObject player = PhotonView.Instantiate(stealthParticle, transform.position, transform.rotation);
}
Answer by Captain_Pineapple · Apr 15, 2019 at 08:23 PM
Hey there,
can you check the code formatting in your post? i think the checkPlayerStealth
function is not displayed correctly.
Anyways: Make sure that you guard any check for key inputs by a check if the script is actually on an object that belongs to the player. This is a rather common mistake when syncing stuff. Also i'd suggest that you do not update something like a stealth status by using the serailization stream. The stealth status is soemthing that will probably change only on a few occasions so it`d be better if you choose a RPC to transfer this information. This will also make things easier when checking for key input.
Let me know if you need further input on this, i'll try to be a bit more precise then.
Hi! thanks for the reply! I'n not sure what you mean by guard any check for key inputs. Could you clarify that please? If you need any additional information on the game for clarification, let me know. Also, sorry about the code formatting. I tried to cut it down because it was really long.
Hey, your uploaded text file does not work for me. It's good that you shortened your code in your original Post! I guess when you deleted parts it also removed some parts that would have defined the start of a function of sort.
Anyways: What i meant by guard is to check if the photonview on the current object actually belongs to the current/local player. You can do this by adding a check: if(photonView.Is$$anonymous$$ine) { "dostuff"}
Additionally i'd strongly suggest as written in my first post that you do NEVER sync a state of a bool via the stream if it only changes once every few seconds or so.
Your answer
Follow this Question
Related Questions
performance question about particles and instantiating 1 Answer
Best way to spread particle system? 1 Answer
How do I make instantiated particles inherit Transform movement from their parent object? 1 Answer
Generating a particle effect on top of a GUIElement 1 Answer
How to Instantiate gameObject where a particle dies 2 Answers