2D shooter tutorial

Discussion in 'Unity Gossip' started by Eric5h5, Dec 20, 2007.

  1. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Messages:
    24,713
    I just put up a tutorial on the wiki here, involving the 2D shooter + level editor project from here. No, this isn't the long-awaited 2D platformer tutorial; it's just something I put together over the last couple of days. It's not about how to create a 2D game, but about working with and extending a Unity project, with some scripting, so I don't think there will be any overlap. At first it was just going to be a brief thing, but somehow it got...longer. I tried not to make many assumptions about the hypothetical reader's abilities, so I guess it's more oriented towards beginners. It could probably use some screenshots. However, I've also attached here an extended version of the project from the above link, with everything from the tutorial up till Part 7, section 2 included (except Part 6, section 1a, 'cause I was too lazy), which might be useful as an illustration if I explained stuff wrong or left something out. Which is likely ;), so let me know about mistakes, etc.

    NOTE: a newer version is available here. It's mostly the same as the attached version, but recompiled as a Unity 4.3 project. I'd replace the attachment here but that doesn't work for larger files anymore, so I'm leaving it for posterity or something...maybe people who for some reason are using an earlier Unity version....

    --Eric

    Attached Files:

  2. taumel

    taumel

    New Member

    Joined:
    Jun 9, 2005
    Messages:
    5,283
    Wow, this looks like you've invested quite some time into it. I only rushed over it but it looks very good!
  3. bigkahuna

    bigkahuna

    New Member

    Joined:
    Apr 30, 2006
    Messages:
    5,419
    Yo Ho Ho, Santa Eric's has delivered goodies for all us little Unitee's! :D
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Messages:
    24,713
    Thanks; hopefully someone gets something from it. Forgot to say, I updated the project from the first link (the non-extended version), so if anyone downloaded that previously, it's been changed a little since then and won't quite work with the tutorial.

    (I don't think Santa says "yo ho ho" unless he's also a pirate with a bottle of rum. ;) )

    --Eric
  5. taumel

    taumel

    New Member

    Joined:
    Jun 9, 2005
    Messages:
    5,283
    /me starts singing Yo-ho, Yo-ho a pirate's life for me!
  6. DaveyJJ

    DaveyJJ

    New Member

    Joined:
    Mar 24, 2005
    Messages:
    1,559
    I now know that Eric IS Santa! Thanks very much for all the gifts during the last few weeks.
  7. drJones

    drJones

    Member

    Joined:
    Oct 19, 2005
    Messages:
    1,352
    wow eric that's awesome - finally got a chance to look at it and its chock full of cool stuff (that level editor is sweet!)

    fantastic work very generous of you ; )
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Messages:
    24,713
    OK, it's been bugging me for days that I didn't implement all the scripting suggestions from the last couple pages of the tutorial, so I went ahead and finished it (except for the "lots o' stuff" part). ;) So now the enemy ships won't crash into walls and they do pathfinding, so they can go around walls instead. Updated project folder above...replace the SimpleEnemy prefab on the Manager script with the Enemy prefab if you want to see the more advanced scripts in action. I updated Part 7 of the tutorial to cover some of the new stuff.

    --Eric
  9. thylaxene

    thylaxene

    Member

    Joined:
    Oct 10, 2005
    Messages:
    634
    Thanks Eric for this great asset and tutorial!

    Cheers.
  10. copenhagenjazz

    copenhagenjazz

    New Member

    Joined:
    Oct 2, 2005
    Messages:
    45
    Thanks Eric :)

    Very helpful to us Unity newbies.

    Happy new year!
  11. tbarbe

    tbarbe

    New Member

    Joined:
    Dec 22, 2008
    Messages:
    154
    hey!

    This is great...Ill dig thru this as well! thank you!

    Looks like there are still lots of people who love the ol 2d!

    ( doh - Im using iPhone Unity - so the types are all required to be strict...do you you have a web based gameplay version of this? )

    cheers,

    Tj
  12. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Messages:
    24,713
    I put #pragma strict on all the scripts...there were only 2-3 lines that needed to be changed after doing that, but here's the whole lot anyway.

    --Eric

    Attached Files:

  13. tbarbe

    tbarbe

    New Member

    Joined:
    Dec 22, 2008
    Messages:
    154
    hey

    this is awesome...thank you for sharing. Its like Asteroids in a cave!

    thank you again.

    cheers,

    Tj
  14. Arges

    Arges

    New Member

    Joined:
    Oct 5, 2008
    Messages:
    359
    Hi Eric,

    I downloaded the code but kept getting the following error on Unity 2.1:

    Assets/2DShooter Assets/Scripts/FPSCounter.js(7,2): BCE0153: 'UnityEngine.RequireComponent' can be applied on one of these targets only : Class.

    I had to replace it with

    @script RequireComponent(GUIText)

    Also, it's amazing how horrible I am at this game. :)
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Messages:
    24,713
    Oops, thought I fixed that ages ago. Anyway you can make levels as easy as you want them to be, so make a level without any enemies, then you will be awesome at the game. ;)

    --Eric
  16. asterix

    asterix

    New Member

    Joined:
    Aug 1, 2009
    Messages:
    245
    I got that error on my pc, unity 2.51

    MissingReferenceException: The variable shootSound of 'BulletControl' doesn't exist anymore. This happened in the game object "Bullet2".
    You probably need to select the "Bullet2" in the hierarchy and reassign the shootSound variable of the 'BulletControl' script in the inspector.
  17. ravens

    ravens

    New Member

    Joined:
    Aug 30, 2009
    Messages:
    125
    Awesome game and scripts Eric5h5, thanks again and a merry yo ho ho with a bottle of brandy! :D
  18. Asvarduil

    Asvarduil

    Member

    Joined:
    Nov 19, 2009
    Messages:
    2,284
    We will all remember this as the day we were given awesomeness by Captain Jac...erm, Eric5h5.

    Yar.
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Messages:
    24,713
    Surely the day to be remembered is December 20, 2007 rather than today.... Thanks though. :)

    --Eric
  20. TwistAU

    TwistAU

    New Member

    Joined:
    Sep 28, 2010
    Messages:
    2
    Well - seems like I'm three years too late for this thread but the tutorial and sample project are both awesome still! :D

    I opened the sample project in Unity 3.0, did the automatic project upgrade it prompts you for and got a bunch of compile errors since it seems that they have made an official Unity class named 'EditorGUI' which conflicts with the script in the sample project. In case anyone's stuck on that I just renamed both the script file and all references to it in LevelEditor.js to 'MyEditorGUI' and now it's working great.

    Thank you Eric!
  21. Eki

    Eki

    New Member

    Joined:
    Feb 2, 2010
    Messages:
    7
    Thank you very much for this.
  22. BerggreenDK

    BerggreenDK

    Member

    Joined:
    Nov 10, 2010
    Messages:
    8
    Anyone got this sample to work with the new Unity3D 3.x ? I am really a newbie here and curious to find out how Unity3D works, compared to Flash and DirectX... I am trying to build some sort of "level loader" with tiles... I have webserver available for assets... just need some sample projects to learn the Unity3D style from.
  23. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Messages:
    24,713
    You need to change all instances of "EditorGUI" to "EditGUI" or something else that's not "EditorGUI", which is an actual Unity class now. In any case I've updated the project.

    --Eric
  24. taumel

    taumel

    New Member

    Joined:
    Jun 9, 2005
    Messages:
    5,283
    Interesting, i thought such things would be automatically corrected if you import an older project into a newer Unity version as well.
  25. BerggreenDK

    BerggreenDK

    Member

    Joined:
    Nov 10, 2010
    Messages:
    8
    aha!, went through all the compiler errors and did as you said. Now I can run the game, but suddently I got a "UnityException: Texture 'wall_corner" is not readable, the texture memory can not be accessed from script.... Dang! I look forward NOT to being a newbie someday.
  26. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Messages:
    24,713
    Did you download from the link (here it is again) rather than the attachment? I should probably just delete that.... Anyway that error means you need to mark the texture read/write enabled in the texture settings, although that's already done in the updated project.

    --Eric
  27. gl33mer

    gl33mer

    Member

    Joined:
    May 24, 2010
    Messages:
    245
    Amazing this project is still so very relevant. Thanks Eric.

    This may just be my next little Unity thing to play with. I've been trying my best to concentrate on C4D tutorials for a while but shall be back to some Unity soon.

    I've got an older project I worked on that was missing a level editor - so, I'm hoping this could be my stepping stone to creating one.
  28. robomaniac

    robomaniac

    New Member

    Joined:
    Mar 24, 2008
    Messages:
    14
    i like a lot that project :D
    has a lot of fun ..
  29. amacgregor

    amacgregor

    New Member

    Joined:
    Jan 6, 2011
    Messages:
    4
    Hey do you have the version of the demo working with Unity3 I been trying to get it work but no look so far.

    Cheers
  30. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Messages:
    24,713
    The link for the Unity 2.6 version in the first post should work fine. It will bring up a message with some scripts that need to be altered, so just click "fix now" and it seems to work with no issues.

    --Eric
  31. HungryHippo

    HungryHippo

    New Member

    Joined:
    Sep 29, 2010
    Messages:
    4
    Hey Eric, this rocks! I've been working with your tutorial and playing with your example project for the last few days and have switched out the graphics with my own to create a pretty neat looking little shooter :)

    I was about to upload my project on Kongregate and release it to the masses, then realised I hadn't actually seen any licensing terms for using your examples and code. If the work I have created takes off on Kongregate am I allowed to sell my work on other platforms? Am I even allowed to upload it to Kongregate? Have you released your work under any specific license? I'm hoping it's public domain so that I can sleep at night without worrying about being sued!! ;)
  32. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Messages:
    24,713
    Yes, it's public domain. Thanks for asking!

    --Eric
  33. vinman

    vinman

    New Member

    Joined:
    Jul 19, 2011
    Messages:
    4
    Can someone help me out? Everytime I do a search this project keeps coming up. Only problem is I can't get it to work. I'm sure I'm doing something wrong. But how do I import this in Unity'? I create a new project, copy the files in windows explorer and reopen the project. This way Unity corrects it for version 3, but all the script references are gone and all I see is a pink plane. If I try to copy it in Unity, all I can copy is the asset folder, but not the library. I'm sure it's an easy mistake, but if someone can help me out that would be great.
  34. Arowx

    Arowx

    Member

    Joined:
    Nov 12, 2009
    Messages:
    2,203
    If you look at the scripts in the IDE you will see that their public variables are listed under the code window, now if you look at the missing links the game objects contain you will see they contain variable details, all you need to do is match them up and re-link the script, it's time consuming and make sure you save often but this approach worked for me.

    Starting from this tutorial I eventually made 'Cure Em Up!' http://cancerwarsgame.org/
  35. vinman

    vinman

    New Member

    Joined:
    Jul 19, 2011
    Messages:
    4
    Thanks for the tips. Not sure what happened, but when I tried again it worked directly. So now I just got to figure it all out. :)

    Liked your game btw, shows how to take a simple concept and expand it with your own ideas...