1. We've introduced thread tags, search within a thread and similar thread search. Read more here.
    Dismiss Notice
  2. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    Dismiss Notice
  3. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  4. We've released our first Timeline Experimental Preview, our new tool for creating cutscenes and more! To check it out click here.
    Dismiss Notice
  5. Unity 5.5 is now released.
    Dismiss Notice
  6. Check out all the fixes for 5.5 in patch releases 1 & 2.
    Dismiss Notice
  7. Unity 5.6 beta is now available for download.
    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:
    417
  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:
    417
    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:
    417
    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

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,503
    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

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,503
    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:
    1
    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:
    2
    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.