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 Tim-A · Dec 02, 2012 at 02:20 AM · network

Unity Network

I'm using the unity networking system. I have 2 cars and a police light. I can turn my own police light on without turning theirs on, but I can't see it in the other screen.

For example, My friend is on his comp, and I'm on mine. I turn my lights on, but he can't see it. What did I do wrong? Here is my code.


 var on : KeyCode;
 var off :KeyCode;
 function Update () {
 
 if (networkView.isMine)
 if(Input.GetKeyDown(on))
 GetComponent(Light).enabled = true;
 
 if (networkView.isMine)
 if(Input.GetKeyDown(off))
 GetComponent(Light).enabled = false;
 }



Thanks, Tim

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
2
Best Answer

Answer by Bunny83 · Dec 02, 2012 at 02:43 AM

No state is transferred automatically to other peers. A NetworkView is responsible vor sync-ing certain informations. The component specified in the observed variable is getting it's public variables serialized and transfered over the net. You need one NetworkView for each component you want to synchronise. An alternative is to observe your script component and implement the OnSerializeNetworkView function. There you can manually specify what data you want transmit.

Note: If you don't implement the OnSerializeNetworkView function, Unity will serialize the public variables of your script when it's observed by a NetworkView.

So one solution should be to add another networkview and drag your light component onto the observed variable. That way all properties should be transferred.

edit

I've just done some tests and it seems Unity only supports a few components to be observed by a NetworkView. A Light component can't be observed (which is a pity, the concept is not bad, but unfortunately they don't stick to it).

So since automatic-synchronising doesn't work with a Light component you have to use OnSerializeNetworkView and let a NetworkView observe your script.

I've created a sample project (including source) which contains the following things:

  • Initializing a server / registrating the server at the MasterServer

  • Connecting to a server (direct connect via IP or via MasterServer game list)

  • Simple chat system

  • Instantiating player objects and synchronising position / velocity of the players rigidbody

  • Syncronising other states like the light status.

  • Sample usage of RPCs

  • Using a texture as color picker

And finally here is a standalone build of the "game" and like always a webbuild (requires the Unity WebPlayer)

This project was done in Unity 3.5.0

Comment
Add comment · Show 6 · 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 Tim-A · Dec 02, 2012 at 02:48 AM 0
Share

Thanks! I'm still a little confused. so I make a script that has an observed variable and what function and what in the script

avatar image Bunny83 · Dec 03, 2012 at 12:54 AM 0
Share

I've updated my answer ;)

avatar image Tim-A · Dec 03, 2012 at 01:01 AM 0
Share

Thanks! Can you save them as .zip not .rar please. I can't open them.

avatar image Bunny83 · Dec 03, 2012 at 01:10 AM 0
Share

:) sure

Here's the standalone build as zip

Here's the project as zip

edit It's 1.5 $$anonymous$$B larger as zip ^^

avatar image Tim-A · Dec 03, 2012 at 01:21 AM 0
Share

Thank you ALOT.

Show more comments
avatar image
1

Answer by TheDarkVoid · Dec 02, 2012 at 03:13 AM

You could also use `networkView.RPC()` to send the data to the peers. This is useful if you only want to send small amounts of data periodicity. Try not the send RPCs every frame, just on a change.

Comment
Add comment · Show 13 · 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 Tim-A · Dec 02, 2012 at 03:45 AM 0
Share

How would I make the lights child the car(atttach to it)?

avatar image TheDarkVoid · Dec 02, 2012 at 06:52 PM 0
Share

i dont understand what your'e asking.

avatar image Tim-A · Dec 02, 2012 at 07:08 PM 0
Share

So, I add a RPC to the lights? How would I do it? Sorry, I wasn't clear.

avatar image FLASHDENMARK · Dec 02, 2012 at 07:15 PM 0
Share

You don't add a RPC to the lights. You add a NetworkView to your lights, and use RPC calls to tell all the other users to turn the light on/off.

avatar image Tim-A · Dec 02, 2012 at 07:17 PM 0
Share

OrangeLightning, I have a network view, but I dont know how to call a RPC on them.

Show more comments
avatar image
0

Answer by zabos · Apr 22, 2013 at 11:45 PM

can you tell me how i can switch on/off the lights with key button insted of gui button?thnx man

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 LightSource · Apr 22, 2013 at 11:44 PM 0
Share

Please post your own question first.

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

15 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

Related Questions

A node in a childnode? 1 Answer

NullReferenceException: Object reference not set to an instance of an object 0 Answers

Information sending frequency 1 Answer

Sending A Variable Over The Network 1 Answer

Network Audio. Why doesnt max distance work over network? 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