Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Unity 5.3] Simple Multiplayer Game Tutorial

Discussion in 'Community Learning & Teaching' started by GTGD, Mar 10, 2016.

  1. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
  2. vanpro

    vanpro

    Joined:
    Jan 3, 2016
    Posts:
    8
    I'm trying to implement player health bar in first person camera mode, but the bar only rotate in server side player. I've synced the y rotation value but the local non-controlled player's bar not rotate accordingly. Would you mind giving a clue for how to do this, thank you.
     
  3. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Don't network health bars, treat them just like the enemy ones
     
  4. vanpro

    vanpro

    Joined:
    Jan 3, 2016
    Posts:
    8
    I didn't network the health bars, but the y rotation of the local player fps camera. Sorry for not mention about that and I not quite understand about your meaning of treating them like enemy. I'm quite new to unity networking and unet anyway.
     
  5. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Study the tutorials, for the player they should see their own health on their HUD canvas. Other players shouldn't see that, instead they should just see a bar that hovers over your players head.
     
  6. Sruthin55

    Sruthin55

    Joined:
    Oct 3, 2015
    Posts:
    3
    Hi I just have a problem with UNET and I've been stuck on for quiet a while now . Here is what I want
    I want the host and the client to be able to instantiate an object

    1. public void objectPlacement() {
    2. if (isLocalPlayer) {
    3. if (Input.GetKeyUp(KeyCode.E))
    4. {
    5. Debug.Log("InsideKeyCodeE");
    6. placedObstaclesCounter++;
    7. Debug.Log ("placedObstaclesCounter");
    8. Debug.Log (playersObstacles.Length);
    9. if (placedObstaclesCounter < playersObstacles.Length)
    10. {
    11. Debug.Log("InsidePlace");
    12. CmdGenerateObstacles ();

    13. Debug.Log("InsidePlace222");
    14. }
    15. else
    16. {
    17. Debug.Log("Player1'sobstacleplacementisdone!");
    18. //lane.transform.position=endPosition.transform.position;
    19. //this.gameObject.SetActive(false);
    20. }
    21. //}

    22. }

    23. }
    24. }

    25. [Command]
    26. public void CmdGenerateObstacles ()
    27. {
    28. Debug.Log("InNetworkSpawn");
    29. GameObject prefab = playersObstacles [placedObstaclesCounter];
    30. spawnPosition = GameObject.Find (thisPlayerName).transform;
    31. GameObject newObstacle = Instantiate (prefab, spawnPosition.position,Quaternion.identity) as GameObject;
    32. movingObstacle = newObstacle;
    33. NetworkServer.Spawn (newObstacle);
    34. newObstacle.transform.parent = localPlayerPlane.transform;
    35. }

    The host is successfully able to spawn an object and works fine , but nothing happens when I try to run it on the client . I have localplayerautority set and all the prefabs have network identity and are set as spoonable objects in network manager . Any help would be greatly appreciated
     
  7. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    To be honest, that health bar was a bit of a hack, as I didn't want to spend the time in this networking tutorial to do health bars correctly. That's more of a ui tutorial. They probably should be tracked in screen space which would require registering them over the network. I have not followed @GTGD 's project, so they may have a better solution.
     
  8. Sruthin55

    Sruthin55

    Joined:
    Oct 3, 2015
    Posts:
    3
    @Adam Buckner I suppose you are representing unity , I have the problem where I'm not able to instantiate an object from the client . I've done a lot of research and above is my code . I'm a student and I've been stuck ob this for a while now , any help would be greatly appreciated
     
  9. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Can you start by listing formatted code? If this is not part of this tutorial series, however, I would suggest starting your own thread, as I would assume @GTGD would like to keep this thread on-topic and related to his recordings of the tutorial series.
     
  10. vanpro

    vanpro

    Joined:
    Jan 3, 2016
    Posts:
    8
    @Adam, the problem been solved after I reviewed the tutorial, thanks.
     
  11. Alacer

    Alacer

    Joined:
    Jun 22, 2016
    Posts:
    14
    Edit: nvm, it works now with if(isServer), dont know why it didnt before.

    My players' healthbars are not updating, or moving at all.
    I tested with a print ("Taken "+amount+" damage."); in the TakeDamage function, and it never reach it.
    My TakeDamage function is this:
    public void TakeDamage(int amount)
    {
    if(!Network.isServer)
    {
    return;
    }
    currentHealth -= amount;
    print ("Taken "+amount+" damage.");
    if(currentHealth <= 0)
    {
    currentHealth = 0;
    print ("Dead");
    }

    }
    Almost same as in the tut, except the if(!Network.isServer), because it throws an error without the Network in front.
     
    Last edited: Jun 22, 2016
  12. AhmedGalal1987

    AhmedGalal1987

    Joined:
    Sep 4, 2016
    Posts:
    3
    Hello everybody,

    I need urgent help .. i have applied changes of enemy prefab wrongly to player prefab!

    Could someone upload his project files or only player prefab on tutorial 13 ??

    Thanks in advance :)
     
  13. Slow-Down

    Slow-Down

    Joined:
    Mar 5, 2016
    Posts:
    1
    Hi everyone,

    I need some help. I used this tutorial creating android fps and my problem is whenever i click, the bullet spawns in different position or like it spawns where I last applied changes to my character. I used button instead of getkey. Any help will be much appreciated. thank you.
     
  14. cocadaboa

    cocadaboa

    Joined:
    Jul 27, 2017
    Posts:
    1
    How can I do to make the movement among players more smooth? I'm having such lag here even changing the variables on network component...
     
  15. viv710

    viv710

    Joined:
    Jul 29, 2016
    Posts:
    8
    Hi All,
    How can i drag the same gameobject in both server and client side and also it should reflect on the other side. (If i am dragging a gameobject from the server side it should reflect on client side and i am selecting the same gameobject from the client and dragging, it should reflect on server side...)
     
  16. TheGameLearner

    TheGameLearner

    Joined:
    Feb 10, 2018
    Posts:
    20
    Hey @GTGD I followed your tutorial and make UI canvas options to playe the game on an android platform... But i am unable to find each other game instance between two android phones. How do I find the players who are connected to the same WiFi connection?
     
  17. deanmayo

    deanmayo

    Joined:
    May 4, 2019
    Posts:
    1
    hi I am at the part of making player movement. I did exactly what you did in the video but my player is not moving!
    can you maybe tell me why or what should I do in order to make player movement.