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 thelime · Jan 14, 2014 at 10:16 PM · multiplayerserverlinerendererclientnetworkview

Missing line renderer in multiplayer?

hi i am doing a game like snake but it is multiplayer and i have this script to spawn a line renderer and multiply SphereCollider after the player that moves around in the game and it works great. i have tested some now and i believe if i slow down the movements of the player it seams to work? but i don't want my player to move in slow motion is there any specific to know about line renderer in multiplayer when using network view?

 using UnityEngine;
 using System.Collections;
 
 public class drawLine : MonoBehaviour {
 
     public LineRenderer lineRender;
     private int numberOfPoints = 0;
     private Vector3 moveDirection = Vector3.zero;
     public float speed = 2.5F;
     public float rotateSpeed = 2.5F;
     public float maxDelay = 5.0F;
     private float delay;
     private Vector3 playerPos;
     private bool firstTimeSpawnCollider;
     private Vector3 spawnColliderPos;
     private bool isAlive;
 
     // Use this for initialization
     void Start () {
         delay = maxDelay;
         firstTimeSpawnCollider = true;
         isAlive = true;
         InvokeRepeating("SpawnPlayerCollider", 0.7f, 0.2F);
 
     }
     
     // Update is called once per frame
     void Update () {
 
         CharacterController controller = GetComponent<CharacterController>();
         if (isAlive) {
                         transform.Rotate (0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
                         Vector3 forward = transform.TransformDirection (Vector3.forward) * speed;
 
                         controller.SimpleMove (forward * speed);
 
                         //if( Input.GetKey( KeyCode.Mouse0 ) ) {
                         numberOfPoints++;
                         lineRender.SetVertexCount (numberOfPoints);
 
                         playerPos = gameObject.transform.localPosition;
     
                         lineRender.SetPosition (numberOfPoints - 1, playerPos);
                 }
     
 
         
 
 
     
     }
     void SpawnPlayerCollider() {
         GameObject player1 = new GameObject( "Player1sCollider" );
 
         if (firstTimeSpawnCollider) {
             spawnColliderPos = playerPos;
 
                         spawnColliderPos.z = spawnColliderPos.z - 2;
                 } else {
         
                 }
 
         
         player1.transform.position = spawnColliderPos;
         player1.AddComponent("SphereCollider");
         SphereCollider player1Collider = player1.GetComponent<SphereCollider>();
         player1Collider.radius = 0.4f;
         player1Collider.isTrigger = true;
         firstTimeSpawnCollider = false;
         spawnColliderPos = playerPos;
         player1.tag = "worm";
     }
     void OnTriggerEnter(Collider other) {
 
         if (other.gameObject.tag == "worm" ||other.gameObject.tag == "wall") {
             
             isAlive = false;
             CancelInvoke();
                 }
 
 
         }
     
 
 
 }
 

But now when i playing in multiplayer so is the line renderer and i believe that SphereCollider is missing for one player? anyone that have any idea why this is happening?

here is the server/client script

 using UnityEngine;
 using System.Collections;
 
 public class NetworkManager : MonoBehaviour {
 
     private const string typeName = "emilswormgame";
     private const string gameName = "RoomName";
     private HostData[] hostList;
     public GameObject playerPrefab;
     public bool firstSpawn;
 
     // Use this for initialization
     void Start () {
         firstSpawn = false;
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
 
 
     private void StartServer()
     {
         Network.InitializeServer(4, 25000, !Network.HavePublicAddress());
         MasterServer.RegisterHost(typeName, gameName);
 
     }
     private void RefreshHostList()
     {
         MasterServer.RequestHostList(typeName);
     }
     
     void OnMasterServerEvent(MasterServerEvent msEvent)
     {
         if (msEvent == MasterServerEvent.HostListReceived)
             hostList = MasterServer.PollHostList();
     }
     private void JoinServer(HostData hostData)
     {
         Network.Connect(hostData);
     }
     
     void OnConnectedToServer()
     {
         Debug.Log("Server Joined");
         SpawnPlayer ();
         //firstSpawn = false;
     }
 
     void OnServerInitialized()
     {
         SpawnPlayer ();
         Debug.Log("Server Initializied");
     }
 
 
     private void SpawnPlayer()
     {
         if (!GameObject.FindGameObjectWithTag("player1")) {
                         Network.Instantiate (playerPrefab, new Vector3 (0f, 4f, -24f), Quaternion.identity, 0);
             firstSpawn = false;
                 } else {
             Network.Instantiate (playerPrefab, new Vector3 (15f, 4f, -24f), Quaternion.identity, 0);
 
                 }
     }
 
 
     void OnGUI()
     {
         if (!Network.isClient && !Network.isServer)
         {
             if (GUI.Button(new Rect(100, 100, 250, 100), "Start Server"))
                 StartServer();
             
             if (GUI.Button(new Rect(100, 250, 250, 100), "Refresh Hosts"))
                 RefreshHostList();
             
             if (hostList != null)
             {
                 for (int i = 0; i < hostList.Length; i++)
                 {
                     if (GUI.Button(new Rect(400, 100 + (110 * i), 300, 100), hostList[i].gameName))
                         JoinServer(hostList[i]);
                 }
             }
         }
     }
 
 
 }


and my playerprefab hase this components;

Mesh Renderer;

DrawLine script (linereanderer and spherecollider sript);

Line Renderer;

character controller;

Network view;

here you can see it

alt text

mask.png (270.5 kB)
Comment
Add comment · Show 1
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 thelime · Jan 15, 2014 at 09:59 PM 0
Share

It seams that it works now when i wait to start the game after every one has joined. Any one that can confirm that it can be so?

0 Replies

· Add your reply
  • Sort: 

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

18 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

Related Questions

Unity networking tutorial? 6 Answers

NetworkViews on Rotating Objects Crash Clients 0 Answers

Networking RPC calls never sent to other clients 1 Answer

Multiplayer push object error. 0 Answers

Character Animation Lags in Multiplayer 2 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