0
\$\begingroup\$

I am currently making a fps multiplayer game, i have successfully made it so that multiple players can join and that they can see each other moving around. However there is a problem with the shooting. While each player can see themselves shoot the only other player they can see shoot is the host, when a client player shoots no one other than the shooter them-self is able to see the projectiles being shot.

Here is the code used to spawn the projectiles:

public GameObject eggPrefab;
public Transform cam;
public float offset;
GameObject eggInstance;
public Animator anim;

// Start is called before the first frame update
void Start()
{
    if (!isLocalPlayer)
    {
        Destroy(this);
        return;
    }
    anim = GetComponent<Animator>();
}

// Update is called once per frame
void Update()
{
    if (Input.GetMouseButtonDown(0))
    {
        anim.SetBool("throwing", true);
        SpawnEgg();
    }
    else
    {
        anim.SetBool("throwing", false);
    }
}

void SpawnEgg()
{
    GameObject instance = Instantiate(eggPrefab, transform.position + (transform.forward * offset), cam.rotation);
    NetworkServer.Spawn(instance);
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.