Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 MadJohny · Mar 05, 2014 at 09:44 AM · c#networkingnetworkrpc

Multiplayer Moving Bullet

Hi, I am trying to make a simple multiplayer bullet that moves through space, the graphics are working, anyway, the player isn't getting destroyed when he gets hit: using System.Collections;

public class LaserScript : MonoBehaviour {

 public float velocity;
 public float radius;
 public float distance;
 public GameObject particles;
 public MeshRenderer[] meshes;
 public Light laserLight;

 void Start () {
     Destroy(gameObject, 10f);
     rigidbody.velocity = transform.forward * velocity;
     if (!networkView.isMine) {
         enabled = false;
     }
 }

 void Update () {
     SphereCastForward();
 }

 [RPC]
 void SphereCastForward () {
     RaycastHit hit;
     if (Physics.SphereCast(transform.position, radius, transform.forward, out hit, distance)) {
         foreach (MeshRenderer mesh in meshes) {
             mesh.enabled = false;
         }
         laserLight.enabled = false;
         Instantiate(particles, transform.position, transform.rotation);
         Destroy(gameObject);
         if (hit.transform.tag == "Head") {
             hit.transform.SendMessageUpwards("ApplyDamage", SendMessageOptions.DontRequireReceiver);
         }
     }
 }

}

So, what could be wrong? This is the mensage that is sent,a long with the part that shoots the bullet:

 void Update () {
 waitTilNextFire -= Time.deltaTime;
 
 if (Input.GetMouseButton(0) && waitTilNextFire <= 0f) {
                 Network.Instantiate (laser, laserSpawner.position, laserSpawner.rotation, 0);
                 waitTilNextFire = fireSpeed;
             }
 }
         void ApplyDamage () {
                 Network.Destroy(transform.root.gameObject);
             }

And if you need the network manager: http://pastebin.com/ryhrfhFq

And here's a script that I got from quil18creates tutorial where he uses photon and tried putting it into unity default networking:

 using UnityEngine;
 using System.Collections;
 
 public class NetworkMovement : MonoBehaviour {
 
     Vector3 realPos = Vector3.zero;
     Quaternion realRot = Quaternion.identity;
 
     void Update () {
         if (!networkView.isMine) {
             transform.position = Vector3.Lerp(transform.position, realPos, 0.1f);
             transform.rotation = Quaternion.Lerp(transform.rotation, realRot, 0.1f);
         }
     }
 
     void OnSerializeNetworkView (BitStream stream) {
         if (stream.isWriting) {
             realPos = transform.position;
             realRot = transform.rotation;
             stream.Serialize(ref realPos);
             stream.Serialize(ref realRot);
         }
         else {
             stream.Serialize(ref realPos);
             stream.Serialize(ref realRot);
         }
     }
 }
Comment
Add comment · Show 7
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 Benproductions1 · Mar 05, 2014 at 10:32 AM 0
Share

I fail to see any code related to networking except for the Network.Destroy which obviously has nothing to do with your error. Please post the code relevant to the error message and delete the rest.

avatar image MadJohny · Mar 05, 2014 at 10:33 AM 0
Share

The Spherecast function should be related to network, since it has [RPC] or am I wrong?

avatar image Benproductions1 · Mar 05, 2014 at 10:36 AM 0
Share

$$anonymous$$aking a function as RPC simply makes it callable across the network. What you do in your function doesn't have to be related to networking in any way shape or form.

avatar image MadJohny · Mar 05, 2014 at 10:42 AM 0
Share

I once made a simple networking script where when you shoot, it would call a new function and shoot a raycast forward, and thens end a message to what it hit, that code was working across the network simply putting [RPC] on it, so what should I change so this works?

avatar image Benproductions1 · Mar 05, 2014 at 10:46 AM 0
Share

As I said, I can only help you once you post all relevant networking code. In the "script" you posted above there is NO networking code what so ever.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Benproductions1 · Mar 05, 2014 at 10:59 AM

I suggest you brush up on how you use RPC's in Unity. You need to use Network.RPC in order for the RPC to be called on other clients.

If you call the function directly you're only doing that, calling the function.

Comment
Add comment · Show 3 · 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 MadJohny · Mar 05, 2014 at 11:22 AM 0
Share

How should I buffer it? RPC$$anonymous$$ode.AllBuffered? And I quite don't udnerstand that, the graphics part were all working, teh meshes and the light was being disabled correctly, but the message wasn't being sent? I mean I disabled the script if the networkView.is$$anonymous$$ine is false, so why does the graphics part work and the message doesn't?

avatar image MadJohny · Mar 05, 2014 at 11:36 AM 0
Share

Player still not getting destroyed, I also get a lot of this errors: https://www.dropbox.com/s/re3gve1c7eo1qlf/Captura%20de%20tela%202014-03-05%2011.36.19.png

avatar image Benproductions1 · Mar 06, 2014 at 06:50 AM 0
Share

@$$anonymous$$adJohny I never said anything about buffering. I merely said you need to use Network.RPC to call your function across the network, because simply calling it directly doesn't do so.

Those errors have to do with your network views. You either don't have one attached on all clients or they all have different ID's.

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

21 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

Related Questions

How To Deal With Lingering Prefabs in Multiplayer Scene ? 0 Answers

Networking RPC sends to wrong target 0 Answers

How can i send a Player list to every Client 0 Answers

RPC and multiplayer networking 2 Answers

Acess server stuff by the client 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