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

GTGD's Unity Multiplayer Tutorials

Discussion in 'Community Learning & Teaching' started by GTGD, Feb 7, 2012.

?

Please select each option you agree with (you can select multiple options)

Poll closed Dec 22, 2015.
  1. I like that the videos are covering a complete project.

    230 vote(s)
    88.1%
  2. I find the videos are detailed enough for me to understand and follow.

    197 vote(s)
    75.5%
  3. I find the video quality is clear enough.

    186 vote(s)
    71.3%
  4. I find the audio quality is clear enough.

    180 vote(s)
    69.0%
  5. The narrator doesn't send me to sleep.

    143 vote(s)
    54.8%
  6. In general the topics covered are interesting.

    170 vote(s)
    65.1%
  7. I find the website useful.

    130 vote(s)
    49.8%
  8. The Gamer To Game Developer logo looks good.

    119 vote(s)
    45.6%
  9. I would like to suggest topics that GTGD should cover in the future.

    103 vote(s)
    39.5%
Multiple votes are allowed.
  1. GrimWinter

    GrimWinter

    Joined:
    Apr 13, 2013
    Posts:
    3
    I took a look at these before and plan to be going through them all soon, thanks a ton for the work you've put into this
     
  2. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Welcome on board and take your time as you go through these tutorials. You'll find the scripts for each video on my website in the downloads section.

     
  3. Ali-Nagori

    Ali-Nagori

    Joined:
    Apr 9, 2010
    Posts:
    151
  4. Howie

    Howie

    Joined:
    Aug 1, 2012
    Posts:
    5
    Has anyone else tried to get this to work with a third person camera system?

    So far I've been able to get multiple players moving on the screen without a problem but I'm having trouble getting the camera to function properly.

    Before I implemented any multiplayer scripts I had one Main Camera in my scene and the player prefab. When the player was spawned the main camera followed him around. When I implemented the multiplayer scripts the networkView.isMine I added to my camera script would always come back as false and disable the script leaving the camera static (I made sure that the network view and MovementUpdate components were added). And if i didn't have any networkView.isMine code it obviously attached itself to the first player to spawn and all additional players only saw that view.

    In order for the network to see my camera I made it a prefab and spawned it in the same way I spawned in the player prefab, but now when more than one player joins it adds multiple main cameras and I think the script is getting confused as to which camera to give function to, because it works ok with the first player but when the second joins it immediately goes to the new camera's view in all instances and doesn't take in any input or know where to look, while the first camera still follows input and knows where to look.

    I'm sure im doing a poor job at explaining this but I'm hoping someone can help. Here is the code that I think it relevant, if you need me to post something else please let me know.

    Here is my spawn script where I'm spawning the Main Camera. In addition to the camerascript my main camera also has the MovementUpdate and Network view components.

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. //Attached to SpawnManager
    5.  
    6. public class SpawnScript : MonoBehaviour {
    7.    
    8.     //used to determine if player needs to spawn
    9.    
    10.     private bool justConnectedToServer = false;
    11.    
    12.     //determine if player is in game
    13.     //public bool AmIInTheGame = false;
    14.    
    15.     //Join window
    16.     private Rect joinGameRect;
    17.    
    18.     private string joinWindowTitle = "Join";
    19.    
    20.     private int joinGameWindowWidth = 330;
    21.    
    22.     private int joinGameWindowHeight = 100;
    23.    
    24.     private int joinGameLeftIndent;
    25.    
    26.     private int joinGameTopIndent;
    27.    
    28.     private int buttonHeight = 40;
    29.    
    30.     //player prefabs are connected to these in inspecter
    31.     public Transform Player;
    32.     public Transform MainCamera;
    33.    
    34.     private int playerGroup = 0;
    35.    
    36.     //Used to capture spawn points
    37.     private GameObject[] spawnPoints;
    38.  
    39.    
    40.  
    41.     void Start()
    42.     {
    43.    
    44.     }
    45.  
    46.     void Update()
    47.     {
    48.    
    49.     }
    50.    
    51.    
    52.     void OnConnectedToServer()
    53.     {
    54.             Debug.Log("Connected to server");
    55.             justConnectedToServer = true;
    56.     }
    57.        
    58.    
    59.    
    60.     void JoinGameWindow(int windowID)
    61.     {
    62.         //if player clicks button he joins the game
    63.        
    64.         if(GUILayout.Button("Join game", GUILayout.Height(buttonHeight)))
    65.         {
    66.             //AmIInTheGame = true;
    67.             justConnectedToServer = false;
    68.             SpawnPlayer();
    69.         }
    70.     }
    71.    
    72.     void OnGUI()
    73.     {
    74.         //if player has just connected then draw join window
    75.        
    76.         if(justConnectedToServer)
    77.         {
    78.             joinGameLeftIndent = Screen.width/2 - joinGameWindowWidth/2;
    79.             joinGameTopIndent = Screen.height/2 - joinGameWindowHeight/2;
    80.            
    81.             joinGameRect = new Rect (joinGameLeftIndent,joinGameTopIndent, joinGameWindowWidth, joinGameWindowHeight);
    82.            
    83.             joinGameRect = GUILayout.Window(0,joinGameRect,JoinGameWindow,joinWindowTitle);
    84.         }
    85.     }
    86.    
    87.     void SpawnPlayer()
    88.     {
    89.         //find spawn points and place reference to them in array SpawnPoints
    90.         spawnPoints = GameObject.FindGameObjectsWithTag("Spawn");
    91.        
    92.         //randomly select a spawn point
    93.         GameObject randomSpawn = spawnPoints[Random.Range(0, spawnPoints.Length)];
    94.        
    95.         //instantiate player and camera at randomly selected spawn point
    96.         Network.Instantiate(Player, randomSpawn.transform.position, randomSpawn.transform.rotation, playerGroup);
    97.         Network.Instantiate(MainCamera, randomSpawn.transform.position, randomSpawn.transform.rotation, playerGroup);
    98.        
    99.         TPCamera.UseExistingOrCreateNewMainCamera();
    100.        
    101.     }
    102.    
    103. }
    104.  

    This is where my camera script takes control of the camera in the scene. Before the multiplayer code i had it check to see if there was a camera in the scene and if there wasn't to add one but decided to try and add the camera in the spawn script instead so I commented out a lot of it.

    Code (csharp):
    1. public static void UseExistingOrCreateNewMainCamera()
    2.     {
    3.         //game objects that hold existing game objects or ones that we create
    4.         GameObject tempCamera;
    5.         GameObject targetLookAt;
    6.         TPCamera myCamera;
    7.        
    8.         //check to see if there is a camera, if not make one
    9.         //if (Camera.mainCamera != null)
    10.         //{
    11.             //assign camera to tempCamera field
    12.        
    13.             tempCamera = Camera.mainCamera.gameObject;
    14.         //}
    15.        
    16.         /*
    17.         else
    18.         {
    19.             //create empty game object names Main Camera
    20.             //add camera component to new game object
    21.             //tag it as the main camera
    22.                        
    23.             tempCamera = new GameObject("Main Camera");
    24.             tempCamera.AddComponent("Camera");
    25.             tempCamera.tag = "MainCamera";
    26.                        
    27.         }
    28.        
    29.         //add TPCamera script to tempCamera
    30.         tempCamera.AddComponent(typeof(NetworkView));
    31.         tempCamera.networkView.observed = null;
    32.         tempCamera.networkView.stateSynchronization = NetworkStateSynchronization.Off;
    33.         tempCamera.AddComponent("TPCamera");
    34.         tempCamera.AddComponent("MovementUpdate");
    35.         */
    36.        
    37.         //store reference to this instance of TPCamera
    38.         myCamera = tempCamera.GetComponent("TPCamera") as TPCamera;
    39.        
    40.         //assign game object called "targetlookat" to targetLookAt field
    41.         targetLookAt = GameObject.Find ("targetLookAt") as GameObject;
    42.        
    43.         //if there is no targetlookat game object make one
    44.         if (targetLookAt == null)
    45.         {
    46.             targetLookAt = new GameObject("targetLookAt");
    47.             targetLookAt.transform.position = Vector3.zero;
    48.         }
    49.        
    50.        
    51.         myCamera.TargetLookAt = targetLookAt.transform;
    52.     }
    53.  
    Thank you very much for any help in advance, and thank you GTGD for these tutorials!
     
  5. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    I think you had better follow this series proper and then once you've understood enough, go your own way and implement the third person camera. What you are talking about is exactly what I explain in Video 2, and then in Video 5 I show you how to have one camera working fine across the network. There only needs to be one camera in the scene and you should avoid spawning it into the game. Whether it is first person or third person is irrelevant as the logic is the same.

    I strongly recommend that you carefully and slowly follow the series for at least the first ten videos and once you've understood the code and logic in those you'll be fine to proceed on your own, and then you'll find that you won't have to spend as much time trying to solve things that aren't difficult at all once you've grasped the logic of how to go about doing things.

     
  6. Howie

    Howie

    Joined:
    Aug 1, 2012
    Posts:
    5
    Thank you for the response GTGD, I went back to video 2 and you're totally right I did miss some stuff and I can see where my logic went wrong with the multiple cameras. I'll re-watch the videos again and see if it makes more sense.

    Thanks again, appreciate it!
     
  7. ratman

    ratman

    Joined:
    May 19, 2013
    Posts:
    2
    hi, i am trying to implement a death counter for each player, but i cant get it to work.
    the strange thing is, Debug.Log("test"); in PlayerScore.cs is never executed.
    there are no exceptions in console.
    hope someone can help me.


    part of HealthAndDamage.cs
    Code (csharp):
    1.  
    2.                             if(myAttacker != ""  myAttacker != "Left Level Bounds")
    3.                             {
    4.                                 GameObject attacker = GameObject.Find(myAttacker);
    5.                                
    6.                                 PlayerScore scoreScript = attacker.GetComponent<PlayerScore>();
    7.                                
    8.                                 scoreScript.iDestroyedAnEnemy = true;
    9.                                
    10.                                 scoreScript.enemiesDestroyedInOneHit++;
    11.                             }
    12.                             PlayerScore scoreScript2 = parentObject.GetComponent<PlayerScore>();
    13.                             scoreScript2.iDied = true;
    14.                             Debug.Log (scoreScript2.iDied);
    part of PlayerScore.cs

    Code (csharp):
    1.  
    2. public bool iDied = false;
    3. public int myDeaths;
    4. void Update ()
    5.     {
    6.        
    7.        
    8.         if(iDied == true)
    9.         {
    10.             Debug.Log("test");
    11.             myDeaths++;
    12.             UpdateDeathsInPlayerDatabase(myDeaths);
    13.             iDied = false;
    14.         }
    15.  
    16.         //When the player destroys an enemy increment the player's score and
    17.         //save their current score in the PlayerDatabase script.
    18.        
    19.         if(iDestroyedAnEnemy == true)
    20.         {
    21.             //enemiesDestroyedInOneHit is a counter and takes into account
    22.             //if the player destroyed more than one enemy in a single hit. If
    23.             //they have then their score should be incremented for each enemy
    24.             //destroyed. This can happen with rockets.
    25.  
    26.             for(int i = 0; i < enemiesDestroyedInOneHit; i++)
    27.             {
    28.                 myScore++;
    29.                
    30.                 UpdateScoreInPlayerDatabase(myScore);
    31.                
    32.                 TellScoreTableToUpdateTeamScore();
    33.             }
    34.            
    35.             enemiesDestroyedInOneHit = 0;
    36.            
    37.             iDestroyedAnEnemy = false;
    38.         }
    39.     }
     
  8. Jakeo-Spikez

    Jakeo-Spikez

    Joined:
    Mar 27, 2013
    Posts:
    8
  9. Howie

    Howie

    Joined:
    Aug 1, 2012
    Posts:
    5
    Awesome, thank you Jakeo, I had EXACTLY the same problem and I fixed it last night exactly the same way. Wish I had found your question earlier would have saved me a lot of time, but I probably learned a lot testing out all my crazy ideas on how to fix it. I don't think I fully understood what I did until I just read your question/solution so that was very helpful. I guess you adapted this networking tutorial for 3dBuzz's third person tutorial as well?

    Thanks again for the response!

    EDIT: Looking at your code a little more carefully, I didn't do it exactly the same way you did and I'm wondering if I would run into any problems leaving it the way I have it.

    This is my TPController
    Code (csharp):
    1. public static CharacterController CharacterController;
    2.     public static TPController Instance;
    3.    
    4.     public static Transform CameraTarget;
    5.    
    6.     void Awake()
    7.     {
    8.         if(networkView.isMine)
    9.         {
    10.             //allows us to reference this class in other classes?
    11.             CharacterController = GetComponent("CharacterController") as CharacterController;
    12.             Instance = this;
    13.            
    14.             CameraTarget = transform.FindChild("targetLookAt");
    15.            
    16.             TPCamera.UseExistingOrCreateNewMainCamera();
    17.         }
    18.         else
    19.             enabled = false;
    20.     }
    and this is my TPCamera

    Code (csharp):
    1. public static void UseExistingOrCreateNewMainCamera()
    2.     {
    3.        
    4.         //game objects that hold existing game objects or ones that we create
    5.         GameObject tempCamera;
    6.         GameObject targetLookAt;
    7.         TPCamera myCamera;
    8.        
    9.         //check to see if there is a camera, if not make one
    10.         if (Camera.mainCamera != null)
    11.         {
    12.             //assign camera to tempCamera field
    13.             tempCamera = Camera.main.gameObject;
    14.         }
    15.         else
    16.         {
    17.             //create empty game object named Main Camera
    18.             //add camera component to new game object
    19.             //tag it as the main camera    
    20.             tempCamera = new GameObject("Main Camera");
    21.             tempCamera.AddComponent("Camera");
    22.             tempCamera.tag = "MainCamera";     
    23.         }
    24.        
    25.         //add TPCamera script to tempCamera
    26.         tempCamera.AddComponent("TPCamera");
    27.            
    28.         //store reference to this instance of TPCamera
    29.         myCamera = tempCamera.GetComponent("TPCamera") as TPCamera;
    30.        
    31.         targetLookAt = TPController.CameraTarget.gameObject;
    32.        
    33.         myCamera.TargetLookAt = targetLookAt.transform;
    34.        
    35.     }
    Will passing it in as a public static transform cause problems down the line you think?
     
    Last edited: May 20, 2013
  10. dstick

    dstick

    Joined:
    May 15, 2013
    Posts:
    4
    These look great! Thanks for creating them. The 'start-to-finish' tutorials are always the best as they teach another valuable skill: finishing a project.
     
  11. Jakeo-Spikez

    Jakeo-Spikez

    Joined:
    Mar 27, 2013
    Posts:
    8
    Looks like it's pretty much the same thing as what I did, just in a slightly different manner. As long as you were finding the child of a script that was attached to the character and not a script that was attached to the main camera.
     
  12. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    I think you don't need a public bool iDied, place the myDeaths++ and associated code within the HealthAndDamage script at the portion that is executed only by the player that is being destroyed "(myHealth <= 0 networkView.isMine == true)". Make sure that your PlayerDatabase script is correctly configured to transmit this message to all the remote players before your player self destructs.

    You need to study the health, damage, and scoring system some more. Watch the videos again if you have to (videos 6 and 9 especially), I know they're long but it's still better than reading through a textbook and you're almost certainly going to pick up points that you missed the first time you watched.

     
  13. ratman

    ratman

    Joined:
    May 19, 2013
    Posts:
    2
    thx, my problem was player was destroyed before messages reached their target.
    0,025 seconds wait time is enough to get it to work :)
     
  14. granzi

    granzi

    Joined:
    Mar 28, 2013
    Posts:
    2
    Beautiful tutorials. I learned a lot and for that I thank you my good man :D Keep doing great work.
     
  15. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    You're quite welcome :D
     
  16. lbarron792

    lbarron792

    Joined:
    Jun 1, 2013
    Posts:
    2
    Hi, I have really been enjoying your tutorials but I ran into a problem after I setup my own spawn script and tested it. everything works except something is wrong with the camera every new person who joins the game is the only person with a camera view for their player. all the other players that joined before switch to the newest camera view. please help if you get the chance.
     
  17. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    You've missed the step where the CameraScript is edited and if(networkView.isMine) is added. This happens while configuring the player in Video 5.

     
  18. lbarron792

    lbarron792

    Joined:
    Jun 1, 2013
    Posts:
    2
    yup I missed that but I found out that wasn't the only thing my player prefab also hadn't saved the settings were I replaced the player camera with the main camera and that was causing problems too thanks for the help and great job on the tutorials.
     
  19. salad__fingers

    salad__fingers

    Joined:
    Aug 11, 2012
    Posts:
    42
    Hi GTGD, thank you a lot for your time to create this. However, I am having a a problem with connecting. I finished the tutorial series, but when I press the button to connect, it does nothing. It acts like a button that doesn't do anything.
    This also happens with attempting to launch a public server.
     
    Last edited: Jun 5, 2013
  20. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Have you followed Series 1? Series 2 is a continuation from Series 1 and the scripts are not going to work without editing unless you are continuing from the Series 1 project.

    Also did you check Run In Background? It's very common for people to miss this step.

     
  21. salad__fingers

    salad__fingers

    Joined:
    Aug 11, 2012
    Posts:
    42
    Okay, I did download series 2 script, figuring they would work. So, I went and downloaded Series 1 to revert back, replaced all the series 2 scripts with the most recent versions of series 1. Now, I can connect, but then there is an empty "Team Select" window, and in the background it says "Red Team Wins" overlapping "Blue Team Wins"
     
  22. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Have you studied all of the series 1 videos and actually built the project? Once you have the built project then you only need to follow the instructions in video 2 of series 2 to upgrade the project to Unity 4. From there you can then implement usage of the master server.

    The information you have written gives me no clear indication of what you are doing or have done, but my distinct impression is that you're rushing through without studying. You won't be able to do much if you don't understand how the code and systems present work.

     
  23. Breden

    Breden

    Joined:
    May 20, 2013
    Posts:
    5
    Thanks GTGD ...its awesome.... i am an average beginner and this helps me alot...
     
  24. Welias D.

    Welias D.

    Joined:
    Jun 12, 2013
    Posts:
    36
    GTGD, Thank you for such a great resource. Community Members like you are just as valuable as the Unity.exe itself!
     
  25. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Thanks for the positive feedback guys!

     
  26. shaal

    shaal

    Joined:
    Apr 28, 2013
    Posts:
    2
    Simply amazing videos. brilliantly done! thanks muchly!
     
  27. chrishall

    chrishall

    Joined:
    Apr 8, 2013
    Posts:
    9
    I keep getting this:

    Assets/Scripts/MulitplayeScript.cs(17,44): error CS0029: Cannot implicitly convert type `string' to `int'
     
  28. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    It just means that you've given the wrong type to a variable. You've declared it as a string but you're trying to use it as an int. Double click on this error in the console log and you'll be shown in Mono where the error arises. The (17,44) is also telling you that the problem is on line 17 in your script.

     
  29. Welias D.

    Welias D.

    Joined:
    Jun 12, 2013
    Posts:
    36
    Having problems passing the playerName to the ConstructionBlock instance...

    There was a need for me to add the player's name to each construction object created during the game play.

    Here is what I have done:

    Since "ConstructionBlockAsksToRemoveItself.cs" is the only script attached to the construction block prefab, add your variable there:

    Code (csharp):
    1.  
    2. public class ConstructionBlockAsksToRemoveItself : MonoBehaviour {
    3.    
    4.     //Variables Start_________________________________________________________
    5.        
    6.     public bool iAmHit = false;
    7.    
    8.     // This is the variable I added:
    9.     public string ObjectOwner;
    10.  
    Now, I will continue to work backwards and open "ServerCreatesConstructionBlock.cs", since this is where the prefab gets instantiated as a gameObject. Go to the bottom of the script where the "CreateConstructionBlock" method is located and modify it like this:

    Code (csharp):
    1.  
    2.     [RPC]
    3.     void CreateConstructionBlock (Vector3 pos, Quaternion rot, string blockNme, string blockOwnr)  // add ", string blockOwnr" here
    4.     {
    5.         block = (GameObject) Instantiate(constructionBlock, pos, rot);
    6.        
    7.         //Assign the unique name to the created block
    8.         //across all game instances.
    9.        
    10.         block.name = blockNme;
    11.        
    12.         //Add these two lines below:
    13.         ConstructionBlockAsksToRemoveItself script = block.transform.GetComponent<ConstructionBlockAsksToRemoveItself>();
    14.         script.ObjectOwner = blockOwnr;
    15.  
    Now look further up in the "ServerCreatesConstructionBlock.cs" script and in the update call change this:

    Code (csharp):
    1.  
    2. networkView.RPC("CreateConstructionBlock", RPCMode.AllBuffered, dropPosition, dropRotation, blockName);
    3.  
    to this:

    Code (csharp):
    1.  
    2. networkView.RPC("CreateConstructionBlock", RPCMode.AllBuffered, dropPosition, dropRotation, blockName, blockOwner);
    3.  
    Now further up to where the variables are declared add this:

    Code (csharp):
    1.  
    2.     public string blockOwner;
    3.  
    Now let's continue going backwards and open "PlayerAsksServerToPlaceConstructionBlock.cs" and near the bottom of the script modify the AskServerToDropConstBlock call to look like this:

    Code (csharp):
    1.  
    2.     void AskServerToDropConstBlock (Vector3 pos, Quaternion rot,string BlockOwnr) // added ", string BlockOwnr"
    3.     {    
    4.         //Find the BlockManager gameObject and assign the position and rotation values
    5.         //to its script ServerCreatesConstructionBlock.
    6.        
    7.         GameObject go = GameObject.Find("BlockManager");
    8.        
    9.         ServerCreatesConstructionBlock script = go.GetComponent<ServerCreatesConstructionBlock>();
    10.        
    11.         script.dropPosition = pos;
    12.        
    13.         script.dropRotation = rot;
    14.        
    15.         script.dropSignal = true;
    16.                        
    17.                 // add this variable setting here:
    18.         script.blockOwner = BlockOwnr;
    19.  
    Now continue back up in this script and change BOTH instances of this line of code:

    Code (csharp):
    1.  
    2. networkView.RPC("AskServerToDropConstBlock", RPCMode.Server, position, hit.transform.rotation);
    3.  
    to look like this:

    Code (csharp):
    1.  
    2. networkView.RPC("AskServerToDropConstBlock", RPCMode.Server, position, hit.transform.rotation, BlockOwner);
    3.  
    Then at the top of this script in the variable declarations area add this:

    Code (csharp):
    1.  
    2.     public string BlockOwner = PlayerPrefs.GetString("playerName");
    3.  
    What is happening is some old cached version of the Registry's memory of PlayerPrefs is getting used.

    Is there a more efficient way to pass the player name to the ServerCreatesConstructionBlock.cs from each player as they call this? Not only does the above not work properly but I would rather not call on PlayerPrefs each time an object is created. I tried referencing playerName but that appears to be a type and not a Global Variable. Where would I set the global variable to make this work if that is an option?

    Thanks!

    EDIT: Ok I have tested it - I compiled with debug and logs - and ran the server and client in different directories and it looks like the playerprefs.get is referring to the previous time I run the server and client. So for example if I run server with a server name of "server 1002pm" and the client with a username of "player 1002pm" then I shut down both and start them over with the server name of "server 1042pm" and the client with username of "player 1042" and I instantiate construction blocks, they show up in the inspector and in debugs as being owned by "player 1002pm"

    odd but it seems like either some script is getting compiled before the other causing a playerprefs.get to pull the prior saved variable or there is something wrong with where or when I am referencing playerprefs.get.

    Is there a better way to set a global variable and just pass it to the server when needed?


    -------------------------------------
    found solution
    -------------------------------------

    This is wrong....

    Code (csharp):
    1.  
    2.     public string BlockOwner = PlayerPrefs.GetString("playerName");
    3.  
    Should just be set in the start function.

    so.....

    at the top of "PlayerAsksServerToPlaceConstructionBlock.cs" we should only declare the variable like this:

    Code (csharp):
    1.  
    2.     public string BlockOwner;
    3.  
    and then add this:

    Code (csharp):
    1.  
    2.     void Start ()
    3.     {
    4.         // Add this here:
    5.         BlockOwner = PlayerPrefs.GetString("playerName");
    6.  

    I would still like to know if there is a more efficient way of getting the player's name and sending it in the network call other than a PlayerPrefs.GetString().

    Thanks!
     
    Last edited: Jun 18, 2013
  30. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Thanks for sharing your code Welias. For the player name you could always have the PlayerName script supply it to the PlayerAsksServer...... scripts so then you'll be sure it's the most up to date name for the player.
     
  31. Tiggster

    Tiggster

    Joined:
    May 22, 2013
    Posts:
    29
    I've just started working through this tutorial series, on video 3 of series 1 at the moment, and am very impressed. I can't wait to get home from work so I can continue. :)

    I apologize if this question has been asked already, but I couldn't find the answer anywhere, so here goes:

    I'm started this project using Unity 4.1.5. So far I've had no issues following along even though the series uses 3.4. Is this going to change as I more forward? I would prefer to work in version 4 if possible, but would downgrade if it was absolutely necessary.

    Any thoughts?
     
    Last edited: Jun 24, 2013
  32. Welias D.

    Welias D.

    Joined:
    Jun 12, 2013
    Posts:
    36
    There are only two areas that the current tutorials differ from the Unity 3 and Unity 4, something to do with ".active = false;" should be ".setActive(false);" If you look at the first video in Series 2 you will see the upgrade procedures from Unity 3 to Unity 4 and it points out the locations of the setActive chagnes.
     
  33. Tiggster

    Tiggster

    Joined:
    May 22, 2013
    Posts:
    29
    Thanks! I think I'll stick with Unity 4.0 for the moment unless it gets too confusing. Seems like an absolutely wonderful tutorial thus far!
     
  34. jzapper

    jzapper

    Joined:
    Sep 1, 2012
    Posts:
    1
    Hi, I downloaded the scripts that are in the video tutorials (Very Great) But i imported them into unity and there were 58 Errors?
    Could you please look through and fix the scripts

    Thanks in advance
     
  35. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Also you'll have some trouble with video 8. The communication window won't work in Unity 4 but video 2 of series 2 shows how the code needs to be changed. If you're sticking with Unity 4 then after you study the communication window portion portion of series 1 video 8 you should then watch series 2 video 2 to understand what needs to be changed. The scripts are also available on my website for each video to help you with that process, but definitely study both videos so that you understand what is changing and why.

     
  36. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    If you're interested in learning then follow the tutorials as you are supposed to. Obviously if you download the scripts and not implement them as per my instructions there are going to be errors.

     
    Last edited: Jun 25, 2013
  37. Tritiko

    Tritiko

    Joined:
    Sep 9, 2011
    Posts:
    6
    Hello! Excuse me for my english I'm from Ukraine and write through Google Translate. I appeal to you for advice. When I add a player Rigidbody. Stops life. HP = 100%. And bullets not see player Collider. And thank you for such wonderful lessons. I have thousands of ideas to create different games now working on creating one of the ideas. Thank you for your attention
     
  38. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Was it working before you added the rigidbody? If it was and if you added another collider then maybe make the trigger collider a bit bigger.

     
  39. Tritiko

    Tritiko

    Joined:
    Sep 9, 2011
    Posts:
    6
    The player has two Box Collider. Everything is working fine. I only adds Rigidbody . Bullets through fly player. And stopped life. I tried to do trigger collider more. Failed then receive the desired result.
     
  40. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    The translation isn't completely clear but I think that you are saying that you have solved the issue you were facing. I should mention that to use a rigidbody on the player for movement you shouldn't use the CharacterController or CharacterMotor script. You'd need to make your own movement script.

    In series 2, which is in development, my player has a rigidbody and I'm writing up my own player control script.

     
  41. Tritiko

    Tritiko

    Joined:
    Sep 9, 2011
    Posts:
    6
    When I add Rigidbody stops working HealthAndDamage. Sorry for the hard to explain in a foreign language root of the problem.
     
  42. Tritiko

    Tritiko

    Joined:
    Sep 9, 2011
    Posts:
    6
    I have a script to move player. Needed to make it work Rigidbody.
     
  43. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Ok I've looked into it and I've also tried out adding a Rigidbody. Yes when I add the rigidbody to the parent suddenly the collider on the Trigger GameObject is no longer being recognised by the raycast on the blaster. So I added a rigidbody to the Trigger GameObject and set it to is Kinematic. I also set the size of the collider on the parent to be just a bit smaller than the collider on the Trigger GameObject. This is to ensure that the blaster sees the collider on the Trigger GameObject first.

    $Added rigidbody to Trigger GameObject.jpg

     
  44. Tritiko

    Tritiko

    Joined:
    Sep 9, 2011
    Posts:
    6
    Thank you very much it works. Дуже вам вдячний за допомогу :) .
     
  45. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Ласкаво просимо. I used Google translate of course :p.

     
  46. dzini

    dzini

    Joined:
    Jun 27, 2013
    Posts:
    1
    hey,l just started coading the multiplayer script and a got to a point in 26 minit and l tried to play the game to see if a menu will popup like in your video but there is only a blue screen and noting else like create a server or join a server.PLS HELLP ME OUT
     
    Last edited: Jun 28, 2013
  47. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Did you attach the multiplayer script to the MultiplayerManager GameObject? Are any red errors appearing in the console?

     
  48. im

    im

    Joined:
    Jan 17, 2013
    Posts:
    1,408
    wow your gtgd is just what i needed! 30 hours of the best tutorial on creating a multiplayer game using unity ive seen!

    would it be possible for your to extend your game and tutorial to use like photon servers and photon cloud.

    thanks in advance!
     
    Last edited: Jul 24, 2013
  49. pixelsteam

    pixelsteam

    Joined:
    May 1, 2009
    Posts:
    924
    GTGD Awesome work.
    I am just about to start onto the series.

    Can I go through the series 1 using Unity 4. As I saw in the second video series there is something about converting to Unity 4.

    Should this concern me?
     
  50. im

    im

    Joined:
    Jan 17, 2013
    Posts:
    1,408
    i just started going through the videos using unity 4.2 so if i run into anything i'll let you'all know, still and so far wow, this guy is great teacher.

    i also made some tweaks, im not sure they are good tweaks but still worth looking at and discussing

    in video 3 he does BlasterScript rewrote it to be more compact and actually be more efficient while still doing the same thing. this is no way to detract from his original work which is amazing on it's own.

    the first change is to Start().

    I replace the call to StartCoroutine(DestroyMyselfAfterSomeTime() with a call to Destroy(myTransform.gameObject, lifespan);

    basically we want to call Destroy() after lifespan of time.

    one good thing with doing the above change is now we don't need call to DestroyMyselfAfterSomeTime() at all so i removed the method entirely. And having less code when possible is always a good thing ;)

    Code (csharp):
    1.  
    2.     // Use this for initialization
    3.     void Start ()
    4.     {
    5.         myTransform = transform;
    6.        
    7.         // As soon as the projectile is created start a countdown
    8.         // to destroy it.
    9.         Destroy(myTransform.gameObject, lifespan);
    10.     }
    11.  
    the second change is to Update()

    i removed

    Code (csharp):
    1.  
    2.                 active = false;
    3.                
    4.                 // Make projectile invisible.
    5.                 myTransform.renderer.enabled = false;
    6.                
    7.                 // Turn off the light and halo.
    8.                 myTransform.light.enabled = false;
    9.  
    because why disable it at all when we can just call Destroy() and be done with it. this also makes it more efficient since the object potentially is destroyed as soon as it hits the floor and does not continue to exist and get calls to update which actually continue to moved until the "Destroy(myTransform.gameObject, lifespan)" is called.

    Code (csharp):
    1.  
    2.     // Update is called once per frame
    3.     void Update ()
    4.     {
    5.         // Move the projectile forward in the directed it is pointed.
    6.         myTransform.Translate(Vector3.up * projectileSpeed * Time.deltaTime);
    7.        
    8.         // If the ray hits something.
    9.        
    10.         if(active  Physics.Raycast(myTransform.position, myTransform.up, out hit, rayRange))
    11.         {
    12.             // If the collider is the floor.
    13.             if(hit.transform.tag == "Floor")
    14.             {
    15.                 // Instantiate an explosion effect.
    16.                 Instantiate(blasterExplosion, hit.point, Quaternion.identity);
    17.            
    18.                 Destroy (myTransform.gameObject);
    19.             }
    20.         }
    21.     }
    22. }
    23.  
    and because of the above change we do longer need

    so i removed it as well. less code always equals joy ;)

    so far so good. i also noticed a small hole in the code. if the object is above the floor and beyond the hit ray's range during call to Update(), but is past (below) the floor during the next call to Update() then Update() will continue to be called and the object moved and be visible until it is Destroyed by the call to "Destroy(myTransform.gameObject, lifespan)". but both his and my tweaked code share the same issue. for that we would have to test if we past the floor, but that is not easy since if we use a short range hit ray shooting back we may miss the fact that we passed the floor and if we use a long one it could be expensive. so im leaving the little hole alone, it wont hurt, this is a video game and not real life, so we don't have to do things perfectly. most likely the player will never know.


    so what do u all think. did i do good, or made a bigger mess of things... ;)
     
    Last edited: Jul 25, 2013