Search Unity

Multiple people on the LAN control the same character.

Discussion in 'Multiplayer' started by The-Game-Master, Aug 28, 2014.

  1. The-Game-Master

    The-Game-Master

    Joined:
    Aug 6, 2014
    Posts:
    54
    I have the following code:
    1. using UnityEngine;
    2. using System.Collections;
    3. public class Network1 : MonoBehaviour {
    4. public Transform PlayerPrefab;
    5. public string Map1 = "Cliffhanger";
    6. // Use this for initialization
    7. void Start () {
    8. }
    9. // Update is called once per frame
    10. void Update () {
    11. }

    12. void OnGUI() {
    13. if (Network.peerType == NetworkPeerType.Disconnected){
    14. GUI.Label (new Rect(400, 50, 240, 100), "Host settings");
    15. GUI.Label (new Rect(400, 440, 100, 40), "Map: " + Map1);
    16. string IP_Address = GUI.TextField (new Rect(10, 90, 300, 100), "IP Adress of host");
    17. GUI.Label(new Rect(10, 192, 100, 100), "Port of host is by default 25001.");
    18. if (GUI.Button (new Rect(10, 30, 120, 20), "Join a game")){
    19. Network.Connect("192.168.4.202", 25001);
    20. Debug.Log ("Joined a game!!!");
    21. }
    22. if (GUI.Button (new Rect(10, 50, 120, 20), "Host a game")){
    23. GUI.Label (new Rect(270, 200, 100, 80), "Don't worry if your game says it's \"Not Responding\", as it is setting up the server. This process could take up to 30 seconds. Thank you for your patience.");
    24. Network.InitializeServer(32, 25001, true);
    25. }
    26. if (GUI.Button (new Rect(340, 200, 120, 20), "Cliffhanger")){
    27. Map1 = "Cliffhanger";
    28. }
    29. if (GUI.Button (new Rect(340, 222, 120, 20), "Pitchfork")){
    30. Map1 = "Pitchfork";
    31. }
    32. else if (Network.peerType == NetworkPeerType.Client){
    33. GUI.Label(new Rect(10, 10, 300, 20), "Status: Connected as a Client");
    34. if (GUI.Button (new Rect(10, 30, 120, 20), "Leave lobby")){
    35. Network.Disconnect(200);
    36. }
    37. }
    38. }
    39. if (Network.isServer)
    40. {
    41. GUI.Label (new Rect (30, 30, 600, 1200), "Players connected:\n" + Network.connections);
    42. }
    43. }
    44. void OnServerInitialized(){
    45. Transform myTransform = (Transform)Network.Instantiate(PlayerPrefab, new Vector3(-130.1763f, 4, -458.5499f), transform.rotation, 0);
    46. }
    47. void OnConnectedToServer(){
    48. Transform myTransform = (Transform)Network.Instantiate(PlayerPrefab, new Vector3(-130.1763f, 4, -458.5499f), transform.rotation, 0);
    49. }
    50. }
    But what happens when the other person joins the game?
    We all have seperate characters, but when they/I look around, it makes me look around as well. When they/I move, it glitches the characters and they all move. I don't understand how to fix this, and I have been at this for 3 days now.