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
1
Question by Fr0stbite · Jun 03, 2013 at 03:39 PM · multiplayermoveclienthost

When i connect to my server the host can't move just the client can move.

pls help the host can't move and watch around here is my script: using UnityEngine; using gui = UnityEngine.GUILayout;

 public class GameMenu : MonoBehaviour
 {
     public GameObject PlayerPrefab;
     string ip = "192.168.1.5";// ip : 127.0.0.1
     static string playername = "Guest";
 
     public void CreatePlayer()
     {
         connected = true;
         var pl = (GameObject)Network.Instantiate(PlayerPrefab, transform.position, transform.rotation, 1);
         pl.camera.enabled = true;
         transform.camera.enabled = false;
         
     }
     void OnDisconnectedFromServer()
     {
         connected = false;
     }
     void OnPlayerDisconnected(NetworkPlayer pl)
     {
         Network.DestroyPlayerObjects(pl);
     }
     void OnConnectedToServer()
     {
         CreatePlayer();
     }
     void OnServerInitialized()
     {
         CreatePlayer();
     }
     bool connected;
     void OnGUI()
     {
         if (!connected)
         {
             ip = gui.TextField(ip);
             playername = gui.TextField(playername);
             if (gui.Button("^2Connect to Match"))
             {
                 Network.Connect(ip, 5300);
             }
             if (gui.Button("^1Host a Match"))
             {
                 Network.InitializeServer(10, 5300, false);
             }
             if (gui.Button("^3Single match"))
             {
                 Application.LoadLevel ("Single");
             }
         }
     }
 }
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 Mahtrok · Jun 03, 2013 at 04:32 PM

I don't think the Error is inside your Network setup but in your move script. Did you deactivate both move & Camera for NetworkPlayers that aren't the active ones? Try Adding

 // c#
 
 void Start () {
      if (!Network.isMine)
           this.enabled = false;
 }
 
 // JavaScript 
 
 function Start () {
      if (!Network.isMine)
           this.enabled = false;
 }
 

to both scripts. If you allready did that it would be nice to see your movement script.

Greetz

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 Fr0stbite · Jun 03, 2013 at 06:23 PM 0
Share

my player prefab hasn't got any script. When the player connect to the server the server just create a player prefab without any script. So i dont use just this script. :D

avatar image Mahtrok · Jun 03, 2013 at 06:58 PM 0
Share

Does he have a CharacterController or how do you move it without any script?

avatar image Mahtrok · Jun 03, 2013 at 07:21 PM 0
Share

To deactivate Cameras and Controllers that aren't the ones the actual client ( or server ) should be able to Access Create two simple scripts, the first one has to be attached to the Camera

Camera: using UnityEngine; using System.Collections;

 public class netCamDeactivator {
      
      void Start () {
           // If is not my Player
           if(!Network.is$$anonymous$$ine) {
                // If there is an AudioListener on your Camera deactivate it
                GetComponent<AudioListener>().enabled = false;
                // Deactivate the Camera
                GetComponent<Camera>().enabled = false;
           }
      }

The second one should be attached to your Player

 using UnityEngine;
 using System.Collections;
 
 public class NetPlayerDeactivator {
 
      void Start () {
           // deactivate the CharacterController that is not $$anonymous$$ine in the Network 
           if (!Network.is$$anonymous$$ine) {
                GetComponent<CharacterController>().enabled = false;
           }
      }
 }

be sure that both player and Camera have a NetworkView, if the Camera is a child Object of the player you may use

      void Start () {  
             // deactivate the CharacterController that is not $$anonymous$$ine in the Network 
               if (!Network.is$$anonymous$$ine) {
                    GetComponent<CharacterController>().enabled = false;
                    GetComponentInChildren<AudioListener>().enabled = false;
                    GetComponentInChildren<Camera>().enabled = false;
               }
          }

then the Camera doesnt have to have a networkView for the player has one. Like this you can activate or deactivate any script or Controller attached to the clients player and ensure that only the one that is the current client may be controlled. For Network is creating local instances of the player on all connected clients and the server, all scripts and Controllers attached to the players Prefab are instantiated as well and in worst case you are moving not only your player around but all connected and Network.Instantiated players by Pressling a key through your Input. Same is for the camera, you will only See the rendered Scene of one of the Cameras on your Screen while all Others are not displayed, so if you deactivate These Cameras not belonging to your current client only the one attached to your player will be displayed.

avatar image Fr0stbite · Jun 03, 2013 at 07:53 PM 0
Share

Ok thanks i'll see that tomorow. Now here the time is 22:52 :D

avatar image Fr0stbite · Jun 04, 2013 at 02:59 PM 0
Share

in the second script i got these errors: Assets/Scripts/NetPlayerDeactivator.cs(8,24): error CS0117: UnityEngine.Network' does not contain a definition for is$$anonymous$$ine'

Assets/Scripts/NetPlayerDeactivator.cs(9,16): error CS0103: The name `GetComponent' does not exist in the current context

the problem was with the networkview it was in unrealible but now the host and the client see different position of the object and everybody move the all players. I know what do you want with that script so i'll try write a script like your

Show more comments
avatar image
0

Answer by Rushabhshroff98 · Dec 01, 2015 at 10:27 AM

Use this

 if(!GetComponent.().isMine){
                     GetComponent.<CharacterController>().enabled = false;
                     GetComponentInChildren.<AudioListener>().enabled = false;
                     GetComponentInChildren.<Camera>().enabled = false;
                     }

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

16 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

Related Questions

Networking sending info only one direction 0 Answers

Multiplayer problem 1 Answer

Multiplayer syncronisation 1 Answer

Stop host without kick clients 1 Answer

How to get the Host's player position ? 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