- Home /
Question by
SterlingStudios · Mar 13, 2018 at 08:27 PM ·
multiplayerguneffect
Multiplayer: Effects not syncing to all users
Hello, I have a problem with my gun muzzle effect not syncing across all users. The effect works and sends to clients when the server fires the gun, however when the client fires the gun it does not send to the server or any another client. Here is the code:
[Client]
void CmdShoot()
{
GetComponent<AudioSource>().PlayOneShot(gunshot);
anim.gameObject.GetComponent<Animation>().Rewind(gunShotAnim.name);
anim.gameObject.GetComponent<Animation>().Play(gunShotAnim.name);
ammo -= 1;
Ray ray = cam.ScreenPointToRay(new Vector3(Screen.width * Random.Range(aimxx.x, aimxx.y), Screen.height * Random.Range(aimyy.x, aimyy.y)));
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 500))
{
if (hit.transform.gameObject.tag == "Enemy")
{
Instantiate(blood, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));
hit.transform.gameObject.SendMessage("Hit", dmg, SendMessageOptions.DontRequireReceiver);
}
if (hit.transform.gameObject.tag == "Stone")
{
GameObject st = (GameObject)Instantiate(stone, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));
NetworkServer.Spawn(st);
}
if (hit.transform.gameObject.tag == "Dirt")
{
Instantiate(dirt, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));
}
if (hit.transform.gameObject.tag == "Metal")
{
Instantiate(metal, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));
}
if (hit.transform.gameObject.tag == "Ragdoll")
{
Instantiate(blood, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));
}
}
RpcMF();
counter = 0;
}
[Client]
void RpcMF ()
{
GameObject mf = (GameObject)Instantiate(muzzleFlash, muzzlePoint.position, muzzlePoint.rotation);
NetworkServer.Spawn(mf);
mf.transform.SetParent(muzzlePoint.transform);
Destroy(mf.gameObject, 0.05f);
}
Any help would be appreciated!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612154530im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
FPS MultiPlayer 2 Answers
How to create a light effect on weapon fire 0 Answers
Need help... Start Button no longer working!!!!! 0 Answers
Cant Kill Multiplayer Player In Unity, Help! 0 Answers
Unity networking tutorial? 6 Answers