Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Finally, an interactive tutorial series that WILL teach you C# for Unity3D

Discussion in 'Community Learning & Teaching' started by SubZeroGaming, Mar 25, 2013.

?

Would you like to see more c# Interactive tutorials?

  1. Yes

    1,401 vote(s)
    98.9%
  2. No

    15 vote(s)
    1.1%
  1. TechnicalArtist

    TechnicalArtist

    Joined:
    Jul 9, 2012
    Posts:
    736
    Usefull tut,thanks for sharing
     
    SubZeroGaming likes this.
  2. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    Thanks for watching!

    Best,

    Jon
     
  3. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    New 2D series released! Moving Platforms!
    Best,
    Jon
     
  4. Valvados

    Valvados

    Joined:
    Jan 27, 2013
    Posts:
    63
    Learning a decent amount in these so far but there's a few things that kind of made me wonder. I'm pretty experienced with unity and how to build things in there which in the beginning I feel more fluent than you were in the video.

    Yet no where near your coding level I thought it would be useful for us to know where you learned coding or what your experience with unity is or maybe just clean up the early videos to make you look more pro than me

    This will be my first language starting to piece lines together alone but having a hard time building an entire class or object.
     
  5. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    Valvados,

    My early videos are from a little over a year ago. I still offer support for those videos, but I don't have the time nor do I feel obligated to clean them up. My new 2D series takes a more professional approach. I self taught myself programming by working on runescape private servers for 4 years. When I hopped over to Unity, I had nothing. I spent a day or two just reading the user manual and figuring out how to do stuff on my own. After fiddling with it, I was like...this is ridiculous...Why isn't there a tutorial out there that shows you how to use the API? So I created one.

    The videos that date back to a year are definitely poorly done, and i'm amazed by how much they help people. Future videos will be more professional and much higher quality as I've gotten more into OOP standards.

    Thanks for watching!

    Best,

    Jon
     
  6. Luftbauch

    Luftbauch

    Joined:
    Jun 16, 2014
    Posts:
    9
    Thank you very much for your work. From my point of view (c+=skill=0) your tutorials are easy to follow.
    You should sell your knowlege as "Instant brain injection" i would buy it..
     
    SubZeroGaming likes this.
  7. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    Ha, thank you very much.
    Glad you're enjoying. Thanks for watching!

    Best,

    Jon
     
  8. Teschio

    Teschio

    Joined:
    Aug 14, 2014
    Posts:
    1
    Kicking myself that it wasn't until 2 days ago that I found your videos and since then I have learnt more in those 2 days than I have been trying for the last 4 months! Seriously well done, subbed and many thanks!
     
    SubZeroGaming likes this.
  9. Ch0nG

    Ch0nG

    Joined:
    Aug 4, 2014
    Posts:
    9
    I just completed the 6th part of the Space Shooter tutorial. Most of it is going well but I've hit a bit of a wall. For some reason my player's z-axis is changing when they are moved horizontally and I can't quite figure out why.

    Here are my scripts; the first one is Player.cs and the second is Laser.cs:
    http://pastebin.com/U6sN9dzv
    http://pastebin.com/VXCAyRy7

    Thanks for any help you can provide!
     
  10. Valvados

    Valvados

    Joined:
    Jan 27, 2013
    Posts:
    63
    Wanted to try and help,
    I think you have too many lines in your player movement

    TS.Translate (Vector3.up * Input.GetAxis("Vertical") * speed * Time.deltaTime);

    specifically ^ that line is giving you some kind of diagonal movement that looks like it's moving on the Z

    just comment that line and it will be fixed.
     
    Last edited: Aug 14, 2014
    SubZeroGaming likes this.
  11. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    Ha, thanks I appreciate it!


    Did Valvados successfully help? I'm on mobile so I'm not able to view it at this time.



    Thanks for helping! :)

    Best,

    Jon
     
  12. Ch0nG

    Ch0nG

    Joined:
    Aug 4, 2014
    Posts:
    9
    @Valvados,
    Thank you for looking at it. After reading your suggestion I gave it a shot but, unfortunately, it did not fix it. I'll keep experimenting and will reply again if I get it figured out.
     
  13. christinanorwood

    christinanorwood

    Joined:
    Aug 9, 2013
    Posts:
    402
    Are you sure you want to use Vector3.up on line 23? With mouse input the vertical axis is forward and back, and usually relates to Vector3.forward.
     
  14. Ch0nG

    Ch0nG

    Joined:
    Aug 4, 2014
    Posts:
    9
    @christinanorwood, I don't necessarily need to use Vector3.up. The character just needs to travel left and right, although I was trying to add the ability to travel up and down as well.

    The strange thing I discovered was that if I change the Vector3 lines to Vector2 (which should eliminate the z-axis) the player's z-axis still changes.
     
  15. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    Thanks for offering help :)

    I just checked out your scripts and I don't see anything that could be causing the z position to change.

    In the inspector, is the z value of the player set to 0?

    I wouldn't really recommend doing this, but you could say in void Update:

    Ts.position = new Vector3(currentX, currentY, 0);

    Let me know if you're still encountering problems.

    Best,

    Jon
     
  16. Ch0nG

    Ch0nG

    Joined:
    Aug 4, 2014
    Posts:
    9
    Yes, upon starting the game the player's z value sets to 0.

    That fixed it. Just to see if can track down the bug I might try re-writing the script sometime soon (probably after I finish the rest of the tutorial). If I figure out what's causing it I'll definitely leave a detailed reply. :)
     
    SubZeroGaming likes this.
  17. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    Thanks, glad it's working :)

    Best,
    Jon
     
  18. Valvados

    Valvados

    Joined:
    Jan 27, 2013
    Posts:
    63
    I finished most of the tutorials accept the 2d series and the GetComponent was a little overwhelming for me today I'll try to get back to those tomorrow. Might do the universal health soon. Have just your newest ones left and 2d games don't interest me at the moment, however I assume over 80% of the C# in those will be useful. Pretty aware of how the graphics work flow is for 2d so wasn't that hyped ill try to skip over those sections as I get to them.

    They're pretty good feel more competent than after doing other tutorials that just seem to give me snippets and familiarize me with stuff that's in the scripting reference.
     
    SubZeroGaming likes this.
  19. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    The 2D series is covering things that you'd see in a platformer, that aren't just 2D related. I go over creating a moving platform in the third one, and that is certainly usable in any environment.

    Thanks for watching!

    Best,

    Jon
     
  20. Ch0nG

    Ch0nG

    Joined:
    Aug 4, 2014
    Posts:
    9
    I just finished the last part of the tutorial and did not re-encounter the previous (z-axis) issue. Everything appears to be working similar to Jon's videos so that's fantastic. :)

    I did try to expand things a bit and I am attempting to add a slightly more advanced spawning of enemies. It spawns additional enemies with a check of the current score or player lives. The spawning (cloning) is successfully but the clones don't move, they just stay where they spawn. :(

    Update: I noticed the Clones do not have a Script attached to them. Once I attached the Enemy script they begin to move. However, if the clones are killed by the player or by running into another enemy the game spawns ~5-10 enemies and freezes.

    Here's my scripts (Player, Laser, Enemy, OnGUI):

    http://pastebin.com/Yjvq8vfB

    http://pastebin.com/bPrR0V58

    http://pastebin.com/pwTWAJLU

    http://pastebin.com/kRnhQQBw
     
    Last edited: Aug 23, 2014
  21. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    Ch0nG,

    Are you doing your spawn manager inside an OnTriggerEnter function? I'm on mobile, but from what i'm seeing, that could be what's causing it to freeze? I suggest creating a new C# script and name it Spawn Manager and an empty gameObject named Spawn Manager and handle all spawning through that. Set your conditions based on the user alive or not or current score there.
     
    Ch0nG likes this.
  22. Ch0nG

    Ch0nG

    Joined:
    Aug 4, 2014
    Posts:
    9
    Jon,

    Yes, that's how I have it. I think it was freezing because the Prefabs were not setup properly so I went ahead and created a new Prefab for the enemies. I then set up the spawning in a new C# script named SpawnManager. The script is called under certain conditions by the Enemy script and spawns additional enemies based on various checks. I included a check on the number of enemies currently "alive" and it prevents the mass spawning issue I had before.

    My code is probably much messier than it needs to be but after some trial-and-error it's working great. I think my next step with it will be experimenting with adding ship graphics/skins for the player and enemies.

    Keep up the good work with the tutorials, too. Your tutorials have me feeling like I can create actual games (and have fun doing it). :)

    Best regards,
    Ch0nG
     
    Last edited: Aug 26, 2014
    SubZeroGaming likes this.
  23. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    Thanks, I appreciate it. Glad you figured it out on your own :)

    Best,
    Jon
     
  24. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    New video out! Understand how LayerMask work and how to bit shift!

     
  25. Thoaril

    Thoaril

    Joined:
    Oct 2, 2014
    Posts:
    4
    Hey Jonathan,

    I just wanted to thank you for your time and efford you put into these tutorials, to teach total strangers like me something.
    It's really very encouraging to try something on your own (for example i just created a quite different version of the space shooter enemies (before even watching the tutorial about it), where they are prefabs sent out by a mothership).

    So thank you again, I will definitly watch every tutorial you provide with great joy!
     
  26. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    Hi,

    Thank you. I really appreciate it. I'm glad you're enjoying the videos.

    Best,

    Jon
     
  27. Thoaril

    Thoaril

    Joined:
    Oct 2, 2014
    Posts:
    4
    Since I fumbled around the last few hours, maybe you could help my with a little problem i've run into.

    I have a Mothership that spawns enemies.
    I did this by using InvokeRepeating in the start funktion, which works great.

    But now I would like to stop the enemies from spawning, if the player gets destroyed.
    for this i already set up a boolean variable (is player alive?).
    The problem is, since the InvokeRepeating is used in the start funktion and (as far as i know) can't be propperly used in the update funktion, i can't change the repeat rate of the Invoke.Repeating.

    So I tried around and thought I found a way using yield WaitForSeconds, but I can't get it to work :(
    Maybe you could take a look and give me a hint?

    Thanks!


    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class EnemyMothership : MonoBehaviour
    5. {
    6.  
    7.     private Transform myTransform;
    8.  
    9.  
    10.     private float MinPosition = 7f;
    11.     private float MaxPostition = -7f;
    12.     private Vector3 EnemyPosition;
    13.  
    14.     private float EnemySpawnRate;
    15.  
    16.     public GameObject EnemyPrefab;
    17.  
    18.  
    19.     IEnumerator InstantiateEnemy()
    20.     {
    21.  
    22.         //generates random position for enemies
    23.         float RandomPosition = Random.Range(MinPosition,MaxPostition);
    24.    
    25.         //stores random position in variable
    26.         Vector3 EnemyPosition = new Vector3(RandomPosition, 10, 0);
    27.    
    28.         //instantiates enemy at random position
    29.         yield return new WaitForSeconds(1);
    30.         Instantiate(EnemyPrefab, EnemyPosition, Quaternion.identity);
    31.     }
    32.  
    33.  
    34.  
    35.     // Use this for initialization
    36.     void Start ()
    37.     {
    38.         myTransform = transform;
    39.    
    40.         //creates an enemy every specified seconds
    41.    
    42.         EnemySpawnRate = 0.8f;
    43.  
    44.     }
    45.  
    46.  
    47.  
    48.     IEnumerator SpawnEnemy()
    49.     {
    50.         yield return StartCoroutine(InstantiateEnemy());
    51.     }
    52.  
    53.  
    54.  
    55.     // Update is called once per frame
    56.     void Update ()
    57.     {
    58.  
    59.    
    60.     }
    61.  
    62.  
    63.  
    64. }
    65.  

    This was the working version with InvokeRepeating:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class EnemyMothership : MonoBehaviour
    5. {
    6.    
    7.     private Transform myTransform;
    8.    
    9.    
    10.     private float MinPosition = 7f;
    11.     private float MaxPostition = -7f;
    12.     private Vector3 EnemyPosition;
    13.    
    14.     private float EnemySpawnRate;
    15.    
    16.     public GameObject EnemyPrefab;
    17.    
    18.    
    19.     void InstantiateEnemy()
    20.     {
    21.  
    22.         //generates random position for enemies
    23.         float RandomPosition = Random.Range(MinPosition,MaxPostition);
    24.        
    25.         //stores random position in variable
    26.         Vector3 EnemyPosition = new Vector3(RandomPosition, 10, 0);
    27.        
    28.         //instantiates enemy at random position
    29.         Instantiate(EnemyPrefab, EnemyPosition, Quaternion.identity);
    30.     }
    31.  
    32.  
    33.  
    34.     // Use this for initialization
    35.     void Start ()
    36.     {
    37.         myTransform = transform;
    38.        
    39.         //creates an enemy every specified seconds
    40.        
    41.         EnemySpawnRate = 0.8f;
    42.  
    43.         InvokeRepeating("InstantiateEnemy",0,EnemySpawnRate);
    44.  
    45.     }
    46.  
    47.  
    48.    
    49.  
    50.     // Update is called once per frame
    51.     void Update ()
    52.     {
    53.  
    54.        
    55.     }
    56.    
    57.    
    58.    
    59. }
    60.  
     
    Last edited: Oct 5, 2014
  28. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    You can always just destroy that spawn manager component, and it will destroy the script.
    You don't have to just destroy gameObjects, you can destroy specified components.
    When the player dies, destroy the EnemyMother ship component. Create a handle to it, and pass it through the Destroy function.
     
    Thoaril likes this.
  29. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    If you want to do it the coroutine route, you will need to constantly have your co routine looping to check if the player is alive.

    while (player is not dead)
    {

    spawn()
    yield return new waitforseconds(spawn delay);

    }
     
  30. Thoaril

    Thoaril

    Joined:
    Oct 2, 2014
    Posts:
    4
    that did the trick! should have thought of that, quite simple!
    thanks for your quick help :)
     
    SubZeroGaming likes this.
  31. WizardGameDev

    WizardGameDev

    Joined:
    Jul 25, 2012
    Posts:
    62
    Hi SubZero... wanted to tell you I like your video series and hope you keep it up!
     
  32. Bromtheman

    Bromtheman

    Joined:
    Feb 2, 2015
    Posts:
    3
    Hey SubZero I have recently been using your space ship game videos to help me make my game, but my game isn't really the same as yours because my game is a fps type game where you can turn and look around, but I am totally stuck on one thing. In your videos you showed us how to make an object shoot a lazer (or in my case for my gun to shoot a bullet) but this is only for one direction in your video. So in my case if I turn around and shoot, my bullet still will go the same direction and will go right through me and continue in that one direction only, so what I want to know is how to make it to where the bullet will go in the same direction as my gun is facing

    Here is the code for my bullet
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Bullet : MonoBehaviour {
    5.  
    6.     public float bulletspeed = 5.0f;
    7.  
    8.     // Use this for initialization
    9.     void Start () {
    10.    
    11.     }
    12.    
    13.     // Update is called once per frame
    14.     void Update () {
    15.         transform.Translate (Vector3.left * bulletspeed * Time.deltaTime);
    16.         Destroy (gameObject, 2);
    17.  
    18.     }
    19. }
    20.  
    -------------------------------
    Here is the code for my gun
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Shoot : MonoBehaviour {
    5.     private Transform myTransform;
    6.     public GameObject Bullet;
    7.     // Use this for initialization
    8.     void Start () {
    9.         myTransform = transform;
    10.     }
    11.    
    12.     // Update is called once per frame
    13.      void Update () {
    14.     if (Input.GetButtonDown ("Fire1")) {
    15.             Vector3 position = new Vector3 (myTransform.position.x, myTransform.position.y, myTransform.position.z);
    16.             Instantiate (Bullet, position, Quaternion.identity);
    17.    
    18.         }
    19.     }
    20.  
    21. }
     
  33. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    What you can do is create an empty gameObject that is a child of your gun...at the tip. And assuming that your tip of the gun aims where you're facing, you can instantiate a bullet and always have it travel in the forward direction. The position wouldn't be your players position, but it would be the tip of the barrels position and have it move in the Z direction.
     
  34. Bromtheman

    Bromtheman

    Joined:
    Feb 2, 2015
    Posts:
    3
    I do have an empty gameobject that is a child of my gun at the tip. Also I changed it to where the bullet goes forward instead of to the left to no prevail as it will still only shoot in one direction it will follow my gun but it will not shoot in the same direction. I recorded a short video to show you what I mean

    Also sorry for the bad quality had to find a fast video recorder
     
  35. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    Ah! It looks like you need to convert local space to world space :)

    We use something in Unity called TransformDirection which takes a direction in localspace and converts it to world space. It's a little confusing to get use to but let me see if i can fix your script a bit.

    And actually, before doing anything with TransformDirection, try this first:

    With transform.Translate you can tell it to move in world space.


    Code (CSharp):
    1. transform.Translate(Vector3.forward* bulletspeed *Time.deltaTime, Space.World);
     
  36. Bromtheman

    Bromtheman

    Joined:
    Feb 2, 2015
    Posts:
    3
    I tried what you said and now my script looks like this for the bullet, but I still have the same problem as it still will not change direction.


    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Bullet : MonoBehaviour {
    5.  
    6.     public float bulletspeed = 5.0f;
    7.  
    8.     // Use this for initialization
    9.     void Start () {
    10.    
    11.     }
    12.    
    13.     // Update is called once per frame
    14.     void Update () {
    15.         transform.Translate (Vector3.forward * bulletspeed * Time.deltaTime, Space.World);
    16.         Destroy (gameObject, 2);
    17.  
    18.     }
    19. }
    20.  
    21.  
     
  37. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008

    I sent you a private message.



    For anyone who's interested, in the next 6 minutes, I'll be hosting a live programming session on google hangout! Free to join: https://plus.google.com/events/crgmjo47dhv63vvifjiad6o76no
     
  38. RealSoftGames

    RealSoftGames

    Joined:
    Jun 8, 2014
    Posts:
    220
    any tutorials on linking scripts together? e.g for example how to make scripts talk? for things like weapon systems, ammo, XP etc. i think that is something i tend to struggle with. getting scripts to talk to each other (or i think it is known as classes)
     
  39. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    Not specifically on classes, and creating base class structures, but I have a GetComponent video which discusses how multiple scripts can communicate and manipulate each others data.
     
  40. RealSoftGames

    RealSoftGames

    Joined:
    Jun 8, 2014
    Posts:
    220
    would i be bale to get a link for that please or a name of the vid if you could?
     
  41. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    Sure :)

     
  42. Levielle

    Levielle

    Joined:
    Feb 25, 2015
    Posts:
    1
    Hello! I am just starting. I just want to know if I have to start from tutorial number one(non-2d) because I don't plan to make 3d games for now because I get nauseous from fps/tps(even by just moving the camera in unity around) or should I just go straight into your 2d tutorials? I want to know if I will miss important lessons(coding wise) not relating to 3d by skipping your first tutorials. Thank you.
     
  43. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008

    Hi, the space shooter series is a 2.5D game. It has some concepts that can certainly be transferred over to the 2D one. With the 2D one, I'm assuming you have knowledge of some basics covered in the space shooter like Triggers, some ray casting, and you'll want to know GetComponent.

    If you're new to Unity, I would at least recommend watching the misc. videos. (Not the space shooter) Just the regular applied to everything videos and then do the 2D.

    Thanks for watching!

    Best,

    Jon
     
  44. yvanbroeck

    yvanbroeck

    Joined:
    Mar 20, 2013
    Posts:
    28
    After a loooong hiatus (Wife, newborn child, new apartment, ... ) decided to get back into Unity and start all over from scratch again. I see you've not been sitting around doing nothing Jon which is great!

    I'll be starting your tutorials again and hopefully refresh a lot of stuff and get started on my own (small) project.
     
  45. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
  46. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    I don't even know where to start! New fundamental series released!
    New Intermediate series released.

    6 videos one day! What?

    Enjoy!
     
    Baldinoboy likes this.
  47. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
  48. CMPN

    CMPN

    Joined:
    Apr 22, 2015
    Posts:
    1
    Wow. I Just cracked Unity last night, making my way through the Roll a Ball tutorial. I decided I needed a deeper dive into the fundamentals of C# and stumbled upon this. Exactly what I was looking for! Your work is much appreciated. Cheers!
     
    SubZeroGaming likes this.
  49. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008

    Thanks, I'm happy you found the channel :) Feel free to make any request you may have on the Facebook page! http://facebook.com/DigitalGamingInstitute
     
    CMPN likes this.
  50. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    like 20 new videos out...Go check them out!

    Enums are up!

     
    Baldinoboy likes this.