Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by nikoyal · Aug 20, 2017 at 04:56 PM · unity 5multiplayermultiplayer-networkingbulletsguns

Bullets showing only on host and weapons not appearing

Hello Im making my first multiplayer game and so far i completed the basic fps tutorial for making it but now i added new bullet types and guns into the game but unfortunately they are only shown on the host's game or so i think because he can shoot and his bullets can be seen but when other player's shoot only ammo is wasted also guns do not appear when i switch them.I tried syncing most of the stuff between the host and the clients but im new to this stuff and if you could possibly explain i would be very happy.

This is my main code :

 using UnityEngine;
 using UnityEngine;
 using UnityEngine.Networking;
 using UnityEngine.UI;
 
 public class PlayerController : NetworkBehaviour
 {
     public Text Ammoleft;
     [SyncVar]
     public int Ak47Bullets = 30;
 
     [SyncVar]
     public int PipeShotgunBullets = 7;
 
     [SyncVar]
     public int currentWeapon;
 
     public Transform[] weapons;
 
     [SyncVar]
     public string CurrentWeaponstr;
 
     public GameObject ShottyBullet;
     public GameObject Ak47Bullet;
     public Transform bulletSpawn;
     public float speed = 1; // speed in meters per second
 
 
     void Update()
     {
         
         if (!isLocalPlayer)
         {
             return;
         }
 
         if(Input.GetKeyDown(KeyCode.Alpha1)) {
             changeWeapon(1);
             CurrentWeaponstr = "Ak47";
         }
         if(Input.GetKeyDown(KeyCode.Alpha2)) {
             changeWeapon(2);
             CurrentWeaponstr = "PipeShotgun";
         }
             
 
         float mouseInput = Input.GetAxis("Mouse X");
         Vector3 lookhere = new Vector3(0,mouseInput,0);
         transform.Rotate(lookhere);
 
         var x = Input.GetAxis("Horizontal") * Time.deltaTime * 3.0f;
         var z = Input.GetAxis("Vertical") * Time.deltaTime * 3.0f;
 
         transform.Translate(x, 0, 0);
         transform.Translate(0, 0, z);
 
         Vector3 moveDir = Vector3.zero;
         //moveDir.x = Input.GetAxis("Horizontal"); // get result of AD keys in X
         //moveDir.z = Input.GetAxis("Vertical"); // get result of WS keys in Z
         // move this object at frame rate independent speed:
         transform.position += moveDir * speed * Time.deltaTime;
 
         if (Input.GetKeyDown (KeyCode.Mouse0) && CurrentWeaponstr == "PipeShotgun" && PipeShotgunBullets > 0)
         {
             CmdFireShotty();
             PipeShotgunBullets -= 1;
             Ammoleft.text = "Left: " + PipeShotgunBullets;
             Debug.Log ("Shotpipe");
         }
         if (Input.GetKey (KeyCode.Mouse0) && CurrentWeaponstr == "Ak47" && Ak47Bullets > 0) {
             CmdFireAk47();
             Ak47Bullets -= 1;
             Ammoleft.text = "Left: " + Ak47Bullets;
             Debug.Log ("ShotAk");
         }
     }
 
     // This [Command] code is called on the Client …
     // … but it is run on the Server!
     [Command]
     void CmdFireAk47(){
         if (CurrentWeaponstr == "Ak47") {
             var Ak47bullet = (GameObject)Instantiate (
                 Ak47Bullet,
                 bulletSpawn.position,
                 bulletSpawn.rotation);
             Ak47bullet.GetComponent<Rigidbody>().velocity = Ak47bullet.transform.forward * 6;
             NetworkServer.Spawn(Ak47bullet);
         }
     }
     [Command]
     void CmdFireShotty()
     {
         
         // Create the Bullet from the Bullet Prefab
         if (CurrentWeaponstr == "PipeShotgun") {
             var Pipebullet = (GameObject)Instantiate (
                              ShottyBullet,
                              bulletSpawn.position,
                              bulletSpawn.rotation);
             Pipebullet.GetComponent<Rigidbody>().velocity = Pipebullet.transform.forward * 6;
             NetworkServer.Spawn(Pipebullet);
         }
 
         // Add velocity to the bullet
 
 
         // Spawn the bullet on the Clients
 
     }
 
     public override void OnStartLocalPlayer ()
     {
         GetComponent<MeshRenderer>().material.color = Color.blue;
     }
         
     public void changeWeapon(int num) {
 
         currentWeapon = num;
         for(int i = 0; i < weapons.Length; i++) {
             if (i == num) {
                 weapons [i].gameObject.SetActive (true);
             }
             else
                 weapons[i].gameObject.SetActive(false);            
         }
     }
 }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by huhund · Aug 20, 2017 at 06:16 PM

Did you remember to add the prefabs to the network manager?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nikoyal · Aug 20, 2017 at 07:09 PM 0
Share

Yes i added them as spawnable prefabs !

avatar image
0

Answer by nikoyal · Aug 21, 2017 at 05:51 PM

I Still need help !

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Joey_pc · Aug 30, 2017 at 05:10 PM

i think you don't to really spawn them just deactivate them and activate them if you need

you can spawn them with [RPC} i think

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

216 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

dedicated server 0 Answers

[UNet] Network Animator transition stutters 0 Answers

UNET Clients Laggy 0 Answers

Instantiated Players Transform Not Changing 0 Answers

UNET (Multiplayer) calling [command] function twice 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges