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 SkizzoTrick · Mar 17, 2014 at 07:28 PM · raycastmultiplayernetworkdamage

How to apply damage to raycast hitten object's Networkview?

Hello, I have a script on an empty gameobject wich includes the next variable: public static float Health;

In another script wich is attached to the player Object i have the next code:

                 hit.transform.gameObject.networkView.RPC ("SetHealth", RPCMode.AllBuffered, 10.0f, hit.transform.gameObject);
                             Debug.Log ("Hitted " + hit.transform.gameObject.name);
                     }
                 }
             }
         }
         
         [RPC]
         void SetHealth(float health, GameObject x)
         {
             if(x.networkView.isMine)
                 Player_stats.Life -= health;
         }

Everything works, it tells me "Hitted player", but it doesn't take his health. It is so stressfull, please help me..

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Robert Carlsson · Mar 17, 2014 at 11:52 PM

The Debug is on "your side" of the RPC call, try putting it inside SetHealth and see if you still get the message. If not the recieving computers never gets the call, do you have an established lan/internet connection?

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 SkizzoTrick · Mar 18, 2014 at 03:00 PM 0
Share

Yes, the multiplayer works perfectly. The only thing is that i do not know how to get the Network View of the object i hit or how to send an execution command for SetHealth function to that specific player.

avatar image Robert Carlsson · Apr 22, 2014 at 04:50 PM 0
Share

So the problem is with the if(x.networkView.is$$anonymous$$ine) then?

Try Setting a Index on each GameObject in a script.

Lets say Player 1 has index 0, set the index on the "Remote" version of him when you enable/instantiate it to 0. Ins$$anonymous$$d of passing a gameobject in the rpc call pass the Index. Then do:

  void SetHealth(float health, int Index)
 {
 if(Index == myIndex)
 Player_stats.Life -= health;
 }

This way you wont have to keep track of the specific networkid but everytime a player joins the game, give him a Index. Then when you spawn his/her unit/character you set his Index in a script both on the local side and remote side.

Sorry for the late reply and I hope that helps!

Regards

avatar image
0

Answer by Wolfrik_Creations · Jun 11, 2016 at 01:40 AM

Two years later and no one has told you that you cannot pass a GameObject through RPC.

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 Robert Carlsson · Jun 21, 2016 at 11:52 AM 0
Share

If you read my latest post you see that I told him to use indexes ins$$anonymous$$d of the GameObjects.

Every client has a list/array of available characters where the characters are given their correct input/actions based on the index the server sends!

And every player gets his/her index assigned as soon as they join the server.

Didn't think I would have to be that specific since I thought he'd read the RPC manual on http://docs.unity3d.com/$$anonymous$$anual/net-RPCDetails.html. There it clearly states it can't be used:

" You can use the following variable types as parameters to RPCs:-

 int
 float
 string
 NetworkPlayer
 NetworkViewID
 Vector3
 Quaternion

"

What I suggested is only one of many ways to handle the issue.

Best Regards

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

22 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

Related Questions

Help|sync movement in multiplayer 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Set unity process as server and client? 0 Answers

Doubt about Network level loading 0 Answers

Can you create a Stand alone server for your game? 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