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 /
avatar image
0
Question by Gaming-Dudester · Mar 26, 2016 at 11:21 PM · multiplayershooting

Multiplayer guns firing at same time

Ok im ginna make this as quick as i can...Multiplayer game with two dufferent types of player prefab. They both have the same gun script. And its this... sing UnityEngine.Networking; using System.Collections; using System; using UnityEngine; using UnityStandardAssets.CrossPlatformInput;

public class shoot : NetworkBehaviour { public Rigidbody Bullet; public float speed = 20f; // Use this for initialization void Start () {

 } 
 
 // Update is called once per frame 
 void Update ()  
 { 
     if (!isLocalPlayer) 
     { 
         return; 
     } 
     if (Input.GetButtonDown ("Fire1"))  
     { 
 
         Rigidbody CreateObjectThing = Instantiate (Bullet, 

transform.position, transform.rotation)as Rigidbody; CreateObjectThing.velocity = transform.TransformDirection (new Vector3 (0, 0, speed));

     } 
 } 

}

This script above ^^^^^^^^ spawns a bullet and then i put a script vvvvvv on the bullet prefab...the script is below.

using UnityEngine; using System.Collections;

public class bulletStuff : MonoBehaviour { public Rigidbody RigidBod; public GUIText textwinned;

 // Use this for initialization 
 void Start ()  

{ }

 // Update is called once per frame 
 void Update ()  
 {         
      
 
 
 
 } 
 
 public void OnCollisionEnter(Collision coll) 
 { 
      
 
 
     if (coll.gameObject.tag == "BulletBreakers")  
     { 
         Destroy (RigidBod.gameObject); 
     } 
     if (coll.gameObject.tag == "PlayerSnoop")  
     { 
         GameObject.Find ("WinScreen").SetActive (true); 
         GameObject.Find ("WinImage").SetActive (true); 
         textwinned.text = ("YAY U WIN, DERP"); 
         Destroy (RigidBod.gameObject); 
     } 
     if (coll.gameObject.tag == "PlayerDerp")  
     { 
         GameObject.Find ("WinScreen").SetActive (true); 
         GameObject.Find ("WinImage").SetActive (true); 
         textwinned.text = ("YAY U WIN, SNOOP"); 
         Destroy (RigidBod.gameObject); 
     } 
 
 
 } 

}

Derp is player 2 and snoop is player one. But the part that is failing is... The update function on the shoot script. The part where it says...

if (!isLocalPlayer) { return; }

It works fine for my player movement script and my player turn script but not for my shoot script...WHYYYYY????

Comment
Add comment · Show 2
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 arksenu · Mar 27, 2016 at 12:42 AM 0
Share

Have you added the script to the game object?

avatar image Gaming-Dudester arksenu · Mar 27, 2016 at 01:18 AM 0
Share

"------->>>>>>>>>AND THEN I PUT A SCRIPT vvvvvv ON THE BULLET prefab...the script is below" i said i did right there.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MCoburn · Mar 27, 2016 at 01:07 AM

So when you fire, both characters guns fire on the client-side, but on the other instance of the game,

For example, here's something I'd do to debug:

1) Get another PC up and running, connect it to Ethernet (LAN) or Wireless. 2) Put a build of the game and connect it to the session that Unity Editor is running. 3) On player 2 (which is the PC, the host is player 1 and that's Unity Editor) shoot your weapon. Watch the editor to see if player 2's gun spawns a bullet or what have you. If it does, good. If the editor's weapon also fires, you've got network events getting called on objects that aren't yours. 4) Do the same from the editor side.

Also, you should always check if the guns from other players are local or not, not bullets. Chances are you're checking if the bullets are local and not the gun, thus when you shoot, everyone else's guns randomly open fire.

Comment
Add comment · Show 2 · 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 Gaming-Dudester · Mar 27, 2016 at 01:19 AM 0
Share

I already did these things. Im asking for the part that says "If (!IsLocalPlayer){}" that part is the part i need help with. Its not working like it does for my other scripts.

avatar image macattackbok · Aug 26, 2020 at 12:31 AM 0
Share

Same Problem. Found a fix?

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

65 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

Related Questions

[Photon] Shoot Projectile multiplayer to mousePos 0 Answers

How to make delay for shooting in Unity/photon 2 0 Answers

How to handle raycast shooting in multiplayer (Mirror)? 0 Answers

UNet Shooting Projectiles easy method? 0 Answers

Spawning objects in multiplayer game 1 Answer


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