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. FikiGames

    FikiGames

    Joined:
    Jan 14, 2013
    Posts:
    7
    For me the most difficult part is to make my character follow my camera movement with mouse look scritp (looking up and down). Any ideas, tutorials? HELP!
     
  2. Sith-Lord

    Sith-Lord

    Joined:
    Feb 1, 2013
    Posts:
    1
    No suport pls help
     
  3. Kaji-Atsushi

    Kaji-Atsushi

    Joined:
    Oct 6, 2012
    Posts:
    234
    I just came across this series, and it looks very promising so far! I've been looking for resources to give me guidelines on how multiplayer networking works.

    Thanks for your hard work to help others!

    I do have a question though, before I dive into your videos. How difficult/adaptable would it be to not use Hamachi to have non-LAN multiplayer, and instead use Photon, or any of the other backend server setups.


    Sorry if my question isn't very clear or answerable, I am new to the networking part of Unity.

    Thanks again!
     
  4. GregMeach

    GregMeach

    Joined:
    Dec 5, 2012
    Posts:
    249
    I posted on youtube but thought I'd post here too. This is the best and most complete series I've found and watched, thank-you so much. As a non-Unity programmer I found the series to be very, very helpful.

    I wanted to also post that I have made several tweaks to the final project and the one I like the most is a revision to the Boundary system (mostly because I couldn't get it to work with my map / layout). Well actually I eliminated it and instead use two cubes with colliders and use the trigger events to warn the player that he is about to leave the area. I also revised the Crosshair script and have it display the warning.

    Revise map:
    Add first cube, use a transparent material for a very cool effect, set it to be 80 less than your map size, add a collider, attach EdgeWarningScript
    Add second cube, set it to be 20 less than map size, add collider, disable mesh, attach EdgeDestroy script
    Note: Remove or disable Boundary script on player objects

    Scripts below:
    EdgeDestroy.cs
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. /// <summary>
    5. /// Edge destroy script.
    6. ///
    7. /// Attached to the map (cube) EdgeDestroy collider, uses the OnTriggerEnter and
    8. /// destroy the player upong entering
    9. /// </summary>
    10.  
    11. public class EdgeDestroyScript : MonoBehaviour {
    12.  
    13.     private Transform myTransform; 
    14.     private bool didEnterZone = false;
    15.        
    16.     void OnTriggerExit(Collider other) {       
    17.         myTransform = other.transform;
    18.         Debug.Log("Destroying: " + myTransform.name);
    19.         didEnterZone = true;
    20.     }
    21.        
    22.     // Update is called once per frame
    23.     void Update () {
    24.         if(Network.peerType == NetworkPeerType.Server) {
    25.             enabled = false;
    26.         }
    27.  
    28.         if(didEnterZone == true) {
    29.             didEnterZone = false;
    30.             Transform trigger = myTransform.FindChild("Trigger");
    31.             HealthAndDamage HDScript = trigger.GetComponent<HealthAndDamage>();
    32.             HDScript.myAttacker = myTransform.name;
    33.             HDScript.iWasJustAttacked = true;
    34.             HDScript.enteredDestroyBoundary = true;
    35.         }
    36.     }
    37.  
    38. }
    39.  
    EdgeWarning.cs
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. /// <summary>
    5. /// Edge warning script.
    6. ///
    7. /// Attached to the map (cube) EdgeWarning collider, uses the OnTriggerExit when leaving the primary
    8. /// zone and thus entering the warning boundary.
    9. ///
    10. /// This script accesses the Crosshair script to set the didEnterWarningZone value
    11. /// </summary>
    12.  
    13. public class EdgeWarningScript : MonoBehaviour {
    14.  
    15.     private Transform myTransform; 
    16.    
    17.     private Crosshair crosshairScript;
    18.    
    19.     // Update is called once per frame
    20.     void Update () {
    21.         if(Network.peerType != NetworkPeerType.Client) {
    22.             enabled = false;
    23.         }      
    24.     }
    25.    
    26.     void GetPlayerObject (Collider other, bool entered) {
    27.         Debug.Log("Warning Zone: " + other.name);
    28.         myTransform = other.transform;
    29.         crosshairScript = myTransform.GetComponent<Crosshair>();   
    30.         crosshairScript.didEnterWarningZone = entered;
    31.     }
    32.    
    33.     void OnTriggerEnter(Collider other) {
    34.         if (other.transform.tag == "RedTeam" || other.transform.tag == "BlueTeam")
    35.             GetPlayerObject(other, false);
    36.     }
    37.    
    38.     void OnTriggerExit(Collider other) {
    39.         if (other.transform.tag == "RedTeam" || other.transform.tag == "BlueTeam")
    40.             GetPlayerObject(other, true);
    41.     }
    42.        
    43. }
    44.  
    Revised:
    Crosshair.cs
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. /// <summary>
    5. /// Crosshair.
    6. /// This script is attached to the player and causes a crosshair to be drawn in the center of the screen
    7. /// This script also displays the warning notice upon entering the warning boundary and accessed by
    8. /// the EdgeWarningScript
    9. /// </summary>
    10.  
    11. public class Crosshair : MonoBehaviour {
    12.    
    13.     public Texture crosshairTex;
    14.    
    15.     private float crosshairDimension = 256;
    16.     private float halfCrosshairWidth = 128;
    17.     private GUIStyle warningStyle = new GUIStyle();
    18.    
    19.     public bool didEnterWarningZone = false;
    20.  
    21.     // Use this for initialization
    22.     void Start () {
    23.    
    24.         if (networkView.isMine == true) {
    25.             warningStyle.fontSize = 24;
    26.             warningStyle.normal.textColor = Color.white;
    27.             warningStyle.fontStyle = FontStyle.Bold;
    28.             warningStyle.alignment = TextAnchor.MiddleCenter;
    29.         } else {
    30.             enabled = false;
    31.         }
    32.     }
    33.    
    34.     void OnGUI ()
    35.     {
    36.         // Display crosshair in center of screen while cursor is locked.
    37.         if(Screen.lockCursor == true) {
    38.             GUI.DrawTexture(new Rect(Screen.width / 2 - halfCrosshairWidth,
    39.                 Screen.height / 2 - halfCrosshairWidth,
    40.                 crosshairDimension, crosshairDimension),crosshairTex);         
    41.         }
    42.        
    43.         if(didEnterWarningZone == true) {
    44.             GUI.Box(new Rect(0,0,Screen.width,Screen.height),"");
    45.             GUI.Box(new Rect(0,0,Screen.width, Screen.height),"!! Turn Back !!\n\nEntered Fatal Destruction Boundary.", warningStyle); 
    46.         }
    47.  
    48.     }
    49. }
    50.  
    Hope it helps someone...
     
  5. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Thanks for sharing GregMeach. I always like seeing how viewers implement or change features for their own projects.
     
  6. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Sorry for taking so long to get back to you. I haven't played around with Photon yet so I wouldn't have thorough knowledge on how difficult it would be to implement Photon. I do believe that you'll have to implement a fair bit of new code though. If you're not making an MMO then maybe you'd be more interested in using the Unity Master Server. I need to get around to producing my next tutorial which will be about making use of the the Master Server so that I can host a public game and not need Hamachi.

     
  7. satre

    satre

    Joined:
    Feb 10, 2013
    Posts:
    12
    Super, thank you very much, waiting for more updates from you!
     
  8. Kaji-Atsushi

    Kaji-Atsushi

    Joined:
    Oct 6, 2012
    Posts:
    234
    No problem, I appreciate the feed back. I'll be looking forward to going through the Master Server tutorial. Do you the key differences/advantages between using Unity Master Server vs Photon? In terms for a FPS type game.

    Thank you for your help, I'm certain the whole community appreciates your videos.
     
  9. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    I'm aware that Photon is used for MMOs as to the best of my knowledge you would actually be hosting a server on a server owned by Photon. Unity Master Server is different and allows you to see and connect to publicly hosted games. Where we host the server is our own business. For a non MMO FPS type game like I'm doing I will go for the Unity Master Server. Players will be able to simply host their own public servers from their own computers and if I wanted to I could make some of my own "official" servers and they would all be visible to players who want to connect to a public server.
     
  10. D3m0nE

    D3m0nE

    Joined:
    Jan 9, 2013
    Posts:
    7
    I Really like ur Tutorials.
    i hope u make a video about how To Make a Button
    to switch Between FPS and 3rdPS view :))

    and How To Make Level System. K/D .. etc :))
     
    Last edited: Feb 20, 2013
  11. Jawad

    Jawad

    Joined:
    Nov 6, 2012
    Posts:
    140
    U r doing great job dear..a bunch of thnx for u...:) keep it up this work...:)
     
  12. nata

    nata

    Joined:
    Jan 9, 2013
    Posts:
    1
    I cant move and move the camera when i am in server, i did what you did, help me please !!
     
  13. AndySaunders

    AndySaunders

    Joined:
    Jan 18, 2013
    Posts:
    17
    Im using unity 4 to create this networked game, but I'm stuck on video 6, If i run the server in unity and connect via a two built versions, the names of the players for red and blue teams do not get passed to player database, only PlayerRed(clone) and PlayerBlue(clone), and so health and damage do not work, I've used your downloaded scripts so these should be ok.

    However if i run one of the built versions as the server and connect via Unity, the player is shown as correct name in GameManager, but the other build version when run at the same time shows as described above does not.

    Any idea's where I need to be looking? should I have created this in 3.4.x and not version 4 to start
     
  14. richardh

    richardh

    Joined:
    Mar 7, 2012
    Posts:
    226
    I think at the beginning of the tutorial GTGD does say that you should use the version he uses. i'm not sure what build that is but it is certainly v3.x

    GTGD what IS the version we should be using? It might be useful to but a 'system/software requirements' info page on your website.
     
  15. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    I've used Unity 3.4.0 in series 1. I do mention that in video 2 and it's also written in the description for each series 1 video. Andy you'll have little choice but to comb through your project and find out what's wrong. From memory it's at video 8 where you'll have trouble with Unity 4 but you can see video S2.2 to understand what to do to get it to work for Unity 4.
     
  16. AndySaunders

    AndySaunders

    Joined:
    Jan 18, 2013
    Posts:
    17
    Thanks for the replies, Ive now restarted with version 3.4.2 and I am up to video 11 with no problems, thanks for the help.

    Looking forward to series 2

    Andy
     
  17. AndySaunders

    AndySaunders

    Joined:
    Jan 18, 2013
    Posts:
    17
    Can someone point me in the right direction, ive added a missile launcher to the game, which detects either red or blue players local to it via a collider and fires a missile at them, but no damage is recorded. Ive also tagged the launcher with redteam and fired at blue team and still no scoring, does this have something to do with the launcher object not being registered in the game like we do for red and blue team, if it is what is the soloution to fix this. the missiles have the blaster script attached.

    Would be really cool to have automatic firing in the game as we travel about the terrain.

    Andy
     
  18. daeuk

    daeuk

    Joined:
    Mar 3, 2013
    Posts:
    67
    Hi guys,

    I am always getting zero on print, thus causing the projectile not to have an angle:
    Code (csharp):
    1.  
    2.     void Start () {
    3.         myTransform = transform;
    4.         cameraHeadTransform = myTransform.FindChild("CameraHead");
    5.     }
    6.    
    7.     // Update is called once per frame
    8.     void Update () {
    9.         if(Input.GetButton("Fire Weapon")) {
    10.             //The launch position of the projectile will be
    11.             //just in front of the CameraHead
    12.             launchPosition = cameraHeadTransform.TransformPoint(0, 0, 0.2f);
    13.             //Create the blaster projectile at the launchPosition
    14.             //and tilt its angle so that its horizontal using
    15.             //the angle eulerAngles.x + 90.
    16.             Instantiate(blaster, launchPosition, Quaternion.Euler(cameraHeadTransform.eulerAngles.x + 90, myTransform.eulerAngles.y, 0));
    17.             print (cameraHeadTransform.eulerAngles.x + 90);
    18.         }
    19.     }
    20.  
    I am using Unity 3.5. Any ideas?
     
  19. ddogave

    ddogave

    Joined:
    Jan 27, 2013
    Posts:
    1
    I am curious how to get sounds into the series 1 game. It would be helpful if you covered that in a future video.

    anyway, I completed series 1 in Unity 4 and didn't have any issues. I used a different skybox and lightmap than the videos because I liked the darker sky better. I had to change the angels on the directional light and change where the lens flare was located to fit the different skybox.

    finished prototype: http://www.davidjdagostino.com/games/multiplayer-first-person-shooter
     
  20. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    @Andy
    The HealthAndDamage script is responsible for applying damage and it needs the name of the player responsible for applying the damage. In a much later video where I have fall damage an empty name for the variable myAttacker is sufficient for a player to get hurt. In your case I think you want the team to get a score when an enemy player is struck and destroyed by the missile launcher so you'll need to edit the HealthAndDamage script and make it understand who is doing the attacking.


    @Daeuk
    I've looked at your code but I couldn't figure out why you're having a problem. Does this only happen when you use the print command or are there further errors shown in the console?


    @ddogave
    Thank you for sharing your completed project! I totally enjoyed playing your version of my project though though I of course prefer the brighter sky and environment more! Good work!

    Adding sound is quite easy. A simple way to add sound is to attach an audio source component to a GameObject and then attach an audio clip to it. You could do this to the blaster projectile and what you'll have is a blaster that emits sound as it flies through the air. You'd disable the audio source once the blaster has struck something. You can alter the audio source component through code as well.

     
  21. daeuk

    daeuk

    Joined:
    Mar 3, 2013
    Posts:
    67
    I am not getting any errors. I think it has something to do with the cameraHeadTransform.

    I cannot get the correct angle and I am only getting 90 when I print it out.

    I mean when I look up above, the angle return by this
    Code (csharp):
    1. cameraHeadTransform.eulerAngles.x + 90
    is always 90.

    Where it should be different right?

    Thanks.
     
  22. rahuxx

    rahuxx

    Joined:
    May 8, 2009
    Posts:
    537
    HiGTGD any planning when you are going to release series 2?
    Rahu
     
  23. richardh

    richardh

    Joined:
    Mar 7, 2012
    Posts:
    226
    I've got a few questions for you GTGD:

    1) Would this tutorial (s1 s2) provide the basis for developing a game that allows players to create accounts to setup their character and which saves to mysql their player prefs?

    2) Would it be possible to use Hamachi to host a persistent server? one that's running all the time?

    3) Would this be possible (1 2 above) using the WebPlayer?

    thanks
     
  24. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    @daeuk, yes the x axis angle should change. Check if the CameraHead GameObject tilts up and down when you move your mouse up and down by selecting the CameraHead attached to the player in the hierarchy panel while the game is running . You should see the x angle in the inspector panel change as you move your mouse up and down. If it doesn't then you may have something missing from video 2. Otherwise I think you'll have to watch video 3 again to find out what is missing.


    @Rahu, Slowly working on it.

    @richardh
    1) No, S1 doesn't cover that and S2 won't either.
    2) Hamachi doesn't host the server. Hamachi is used to make it easier for people to connect across the internet without having to use port forwarding. You still have to use your own computer to host your own server so if your computer crashes the server is going down.
    3) The web player can be used for running a server but web browsers crash quite easily.

    For hosting your server you should look into Photon or setting up your own Master Server arrangement.

     
  25. Rheeenz!

    Rheeenz!

    Joined:
    Nov 23, 2012
    Posts:
    7
  26. hike1

    hike1

    Joined:
    Sep 6, 2009
    Posts:
    401
    On video 3 basic projectile I'm only firing 5 projectiles then it quits and I get this error


    MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.

    Instantiate(blaster,launchPosition,Quaternion.Euler(cameraHeadTransform.eulerAngles.x + 90,
    myTransform.eulerAngles.y, 0));

    Also I dragged Blaster and Blaster Explosion into the scene, but they don't seem to be in your scene, if I delete them -no shooting.
    Scene attached, requires 1st person controller and particles from Standard Assets.
     

    Attached Files:

  27. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    @Rheeenz. No I don't have any tutorials for such a game but the programming for that is easier than an FPS so if you keep studying how to code in Unity you'll be able build that type of game by yourself. For that type of game the story, artwork and atmosphere will be much more of a challenge to develop than the coding.

    @hike1, Sorry I can't debug your project for you as I don't have time for that. You'll need to watch the video again and I also recommend that you compare your code line by line against mine. You can download my scripts from my website.

    It's possible that you may have setup your GameObjects incorrectly. Check what you attached the FireBlaster script to and whether you have correctly attached the Blaster into the public variable slot of the FireBlaster script. A MissingReferenceException error means that the script is trying to access something that doesn't exist. In other words the script can't find what it is supposed to access.

     
  28. hike1

    hike1

    Joined:
    Sep 6, 2009
    Posts:
    401
    I started over, no errors now rockets instantiate but don't move
     

    Attached Files:

  29. rahuxx

    rahuxx

    Joined:
    May 8, 2009
    Posts:
    537
    HI GTGD, can you add some video tutorials regarding asset streaming through asset bundle/
    It will be great help to me.
    rahu
     
  30. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    @ hike1. Check that you've attached a script to allow the rockets to be propelled. For example, in video 3 I attach the BlasterScript to the blaster projectiles.

    @rahuxx. No I won't be covering that. I believe that is a Unity Pro feature.

     
  31. Deleted User

    Deleted User

    Guest

    My startingpoints is towers with an attached flag and my players have a face :cool:

    $multiplayerBlueTower.png $multiplayerRedPlayer.png

    THANK YOU ever so much!! This video-serie you've done is absolutely awesome! I learned so much and I have a nice little multiplayer-game to play with now:D
    The way you explained and showed makes it easy to test out own changes in scripting etc. First time in my life I've used C# and not long ago it scared me to death to just think of me wiring games myself. I've built games in Blender and Max earlier, and used a bit of python and java but C# always seemed so daunting. And now I even understand what the error-messages tell me /thumbs up to an excellent teacher!
     
  32. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Awesome to see that you've gone through and completed the project ametist! Good luck in your future projects!
     
  33. hike1

    hike1

    Joined:
    Sep 6, 2009
    Posts:
    401
    quote
    @ hike1. Check that you've attached a script to allow the rockets to be propelled. For example, in video 3 I attach the BlasterScript to the blaster projectiles
    unquote

    Yep, that was the problem, now they fire. But the player isn't firing up or down, only horizontal. I just have the regular FPS controller with the
    CameraHead child and camera.cs, would that mess up the mouselook?
     
  34. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    You need to attach a Mouselook script to the CameraHead. Hike1 you have to go back and watch video 2 again because it's more than likely that you've missed other stuff and you will have trouble progressing if you have. Don't watch the videos when you're tired, you won't be able to concentrate as my speech isn't the type that will keep you awake. Following these videos is studying and of course studying anything requires concentration in order to be successful.

     
  35. hike1

    hike1

    Joined:
    Sep 6, 2009
    Posts:
    401
    Got it, at 54:37 put a mouselook.cs- Y axis only- on the CameraHead. I get why the CameraHead is there, for multiplayer ownership, but I'm not making
    a multiplayer game at the moment. I just need a few parts, rockets, particle cannon, got the water already. Videos are important, but they should all
    come with an html with the main points, or a transcript at least.
     
  36. games

    games

    Joined:
    Feb 18, 2012
    Posts:
    61
    Best series ever!

    Did bajeo ever share his code for integrating the master server with your code?

    Thanks!
     
  37. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    No he didn't post up his code from what I can remember. Anyhow I am supposed to get a video out showing how to use the Unity Master Server and I do actually have it working but I just need to figure out how to show the ping of each public server listed. My development pace has been slowed down to a crawl due to me having less free time but I'm aiming to make some progress this Easter break. If I don't figure out how to implement ping in the next few weeks then I'll just make a video without it, at least public servers will be listed and people can host their own public servers, then later on I'll make a video implementing ping when I've figured it out.

    Also I'll have to make a video later on that shows how to setup your own master server because Unity's is only for testing and not for finished games.

     
  38. yvanbroeck

    yvanbroeck

    Joined:
    Mar 20, 2013
    Posts:
    28
    Thanks a lot for these mate!
     
  39. games

    games

    Joined:
    Feb 18, 2012
    Posts:
    61
    That is excellent news! Your effort with this is simply inspirational. I've literally learned C# and networking all thanks to you. Cheers!
     
  40. hike1

    hike1

    Joined:
    Sep 6, 2009
    Posts:
    401
    quote
    Got it, at 54:37 put a mouselook.cs
    unquote

    I made a prefab of the player/blaster/explosion/camerascript, etc. When I put it in an new scene with a "Main Camera" it works but doesn't work in
    a scene without a Main Camera, if I make a camera and name it "Main Camera" only the Main Camera view is seen in game, while the Player is moving around blind.
    //////
    Is there a way to rewrite the FireBlaster.cs to child it to a camera childed to the FPS controller only, and bypass this camerahead thing?

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    using UnityEngine;
    using System.Collections;

    /// <summary>
    /// This script is attached to the player and it
    /// causes the camera to continuously follow the
    /// CameraHead.
    /// </summary>


    public class CameraScript : MonoBehaviour {

    //Variables Start___________________________________

    private Camera myCamera;

    private Transform cameraHeadTransform;

    //Variables End_____________________________________


    // Use this for initialization
    void Start ()
    {
    myCamera = Camera.main;

    cameraHeadTransform = transform.FindChild("CameraHead");
    }

    // Update is called once per frame
    void Update ()
    {
    //Make the camera follow the player's cameraHeadTransform.

    myCamera.transform.position = cameraHeadTransform.position;

    myCamera.transform.rotation = cameraHeadTransform.rotation;
    }
    }


    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     
  41. hike1

    hike1

    Joined:
    Sep 6, 2009
    Posts:
    401
    This might be what I'm after, it's even shorter than Ali's

    http://unity3d.com/learn/tutorials/modules/beginner/scripting/instantiate

    //UsingInstantiate.cs
    public class UsingInstantiate : MonoBehaviour
    {
    public Rigidbody rocketPrefab;
    public Transform barrelEnd;


    void Update ()
    {
    if(Input.GetButtonDown("Fire1"))
    {
    Rigidbody rocketInstance;
    rocketInstance = Instantiate(rocketPrefab, barrelEnd.position, barrelEnd.rotation) as Rigidbody;
    rocketInstance.AddForce(barrelEnd.forward * 5000);
    }
    }
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////

    And the projectile has this script


    //RocketDestruction.cs

    using UnityEngine;
    using System.Collections;

    public class RocketDestruction : MonoBehaviour
    {
    void Start()
    {
    Destroy (gameObject, 1.5f);
    }
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    I just need to put the bit about 'firerate' and 'nextfire' in the UsingInstantiate so it's not so fast, and the stuff from BlasterScript that makes an explosion
    if it hits anything tagged Floor.

    1 thing going on with the BlasterScript.cs is that the particles aren't disappearing even though I have 'autodestruct' checked on the particle system.
     
  42. hike1

    hike1

    Joined:
    Sep 6, 2009
    Posts:
    401
    quote
    but doesn't work in
    a scene without a Main Camera,
    unquote

    To make a "Main Camera" , add a "Camera" and then Tag it "Main Camera" DOH!
     
  43. atsanche

    atsanche

    Joined:
    Apr 13, 2013
    Posts:
    2
    First and foremost your tutorials are excellent and your are doing us all a great service by offering these. Now to my stress, I am encountering an error near the end of 1.5 where i am locking the cursor. I was getting response and everything was working fine but now I get this error in the console when i run as client, hosting the server on a separate build:

    Code (csharp):
    1. NULLReferenceException: Object reference not set to an instance of an object
    2. Cursor Control.Update( at Assets/Scripts/CursorControl.cs: 30)
    Line 30 verbatim is:

    Code (csharp):
    1.  
    2. if(multiScript.showDisconnectWindow == false) {
    3.  

    I have no idea what I am doing wrong, please help :)
    Sorry if this is a duplicate thread, couldn't find anything per say.

    UPDATE: Ive never had movement displayed on the server. Further more all my scripts are being unchecked on joining the server, any ideas?
     
    Last edited: Apr 14, 2013
  44. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Check that showDisconnectWindow in the multiplayerscript has been turned into a public variable. The NullRefernce means that something can't be found and so the CursorControl script is unable to find multiScript or more likely it's unable to find showDisconnectWindow.

     
  45. atsanche

    atsanche

    Joined:
    Apr 13, 2013
    Posts:
    2
    HA! Fixed, your amazing!

    The next problem involves my two players talking to each other. This is weird. I am able to create the LAN Hamachi server and add one player successfully and have all its movement echo back to the server. As soon as the second player is added its controls and camera switch to the first player that entered, if i shoot on the second player computer i can see it shoot from the correct capsule and the camera moves with the mouse but no movement. Aren't these player scpecific or is it attaching to the main camera? Not sure.
     
  46. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    I think you might have missed an if(networkView.isMine == true) bit of code in the CameraScript and maybe somewhere else. I think you'll need to watch the video again carefully and make sure you don't miss anything. Take your time while following the tutorials.

     
  47. helloiam

    helloiam

    Joined:
    Oct 11, 2012
    Posts:
    2
    Right now I am working on my network skills but at moment I am dealing with a small issue. A server opened I am accesing with 2 players into the server, but the main problem is that the player 1 uses his own camera but player 2 looks not trough his own camera but trough the camera of player 1.

    In short: Player 2 is not looking through his own main camera but trough the camera of Player 1. I want that both of the players are using his own main camera.

    Huge thanks for reading and helping!
     
  48. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    As per the message I sent back to you, you've missed editing the CameraScript.

     
  49. technotdc

    technotdc

    Joined:
    Oct 21, 2011
    Posts:
    60
    Hello ....
    I have a script, called zoom, added to the main Camera .......

    Code (csharp):
    1.  
    2. var zoom : int = 20;
    3. var normal : int = 60;
    4. var smooth : float = 5;
    5.  
    6.  
    7.  
    8. private var isZoomed = false;
    9. public var SniperActive = false;
    10.    
    11. function Update () {
    12.  
    13.      Zoom();
    14.      
    15.   }
    16.  
    17.  
    18.  
    19.  
    20. function Zoom () {
    21.  if(Time.timeScale != 0){
    22.         if(Input.GetMouseButtonDown(1)){
    23.             isZoomed = true;
    24.         }else if(Input.GetMouseButtonUp(1)){
    25.             isZoomed = false;
    26.         }
    27.         if (SniperActive==true) {
    28.         if(isZoomed == true){
    29.             camera.fieldOfView = Mathf.Lerp(camera.fieldOfView,zoom,Time.deltaTime*smooth);
    30.         }
    31.         else{
    32.             camera.fieldOfView = Mathf.Lerp(camera.fieldOfView,normal,Time.deltaTime*smooth);
    33.         }
    34.        
    35.       }
    36.  
    37.  }
    38.  
    39.  

    How can send a message from changeWeapon script to put TRUE the variable SniperActive ? (well, when Blaster is selected)

    (I watched sendmessage reference but I cant do it ...)


    thanks
     
  50. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Why can't you set a reference to this script called Zoom using the typical gameObject.GetComponent<Zoom>() and then just access the public variable? I do that all the time in so many of my scripts. I prefer not to do a blind sendmessage because it makes the code harder to debug or change when you look at it some months down the line.