Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

shooting projectile

Discussion in 'Multiplayer' started by aokiji99, Sep 12, 2017.

  1. aokiji99

    aokiji99

    Joined:
    Apr 2, 2017
    Posts:
    7
    ok i have this code

    void Update()
    {
    if (Input.GetKey(KeyCode.F))
    {
    if (Time.time > shootRateTimeStamp)
    {
    GameObject go = (GameObject)Instantiate(bullet, gun.position, gun.rotation);
    NetworkServer.Spawn(bullet);
    go.GetComponent<Rigidbody>().AddForce(gun.forward * shootForce);
    shootRateTimeStamp = Time.time + shootRate;
    }
    }
    }


    but the bullet doesnt spawn in the other client how can i make so that the bullet spawn and move in the other client
     
  2. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    The code is being ran on the client. Execute it on the server with a RPC
     
  3. aokiji99

    aokiji99

    Joined:
    Apr 2, 2017
    Posts:
    7
    sorry i am kinda a newbie how can i do that and can i make it so that the bullet belong to the player that shoot it?
     
  4. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Command calls for client to server rpc. And spawn with authority to give authority