Search Unity

I know C# and tried Unity 3D tutorials but how do i create my own gameplay scripts?

Discussion in 'General Discussion' started by Death_Skull_DX, Aug 19, 2014.

  1. Death_Skull_DX

    Death_Skull_DX

    Joined:
    Aug 17, 2014
    Posts:
    7
    Basically, after learning C++ for 3 months and after some programs that i made, i wanted to move on to game development to create a 3rd Person Stealth game because i find the Stealth Genre very fascinating and exhilarating.

    However, I knew that i had to learn OOP and C++ was still difficult to work with even though i knew it quite well since knowing syntax and how things work is completely different to designing a good program that works with libraries that i never knew about.

    So I saw Unity 3D and it impressed me so much that i wanted to create my game with it, I was able to quite quickly pick up C# in 2 weeks and knew its syntax very well since i worked in C++ and got used to C++.

    But after trying out the stealth and rolling ball tutorial and etc. After reading the documentation for a week , I started getting very frustrated because i simply don't know how to create my own scripts.

    I don't know what functions/Variables to use. I just don't know how to create my scripts, where should I search in the API.

    I became very frustrated and just couldn't understand how to create my own scripts or what I use to create them. I did read all of the tutorials and such but i still don't know what to do.

    Does anyone have any good advice?

    EDIT: Sorry i posted this in the wrong section. Could a mod move this if possible? Thanks.
     
  2. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    my signature. I go through an interactive approach that teaches how to write from scratch using the unity API.

    Best,

    Jon
     
  3. RvBGames

    RvBGames

    Joined:
    Oct 22, 2013
    Posts:
    141
    @DSDX, may I call you that? What is it that you're trying to do?

    To be honest some of the issues that you're facing have more to do with experience than knowing a particular language.

    Have you looked at other websites such as:

    http://unitygems.com/

    This one is a little more technical but is valuable all the same:

    http://scrawkblog.com/

    There are others too, I just don't remember them. Maybe if I get the time, and so inclined, I'll try to compile a list of good sites.

    Again, do you have something specific that you're trying to do? Something simple possibly?
     
  4. Death_Skull_DX

    Death_Skull_DX

    Joined:
    Aug 17, 2014
    Posts:
    7
    @rvb Games Sure i am fine with that :) !

    Thank you for your advice and I am trying to to create a simple 3rd Person camera character controller that has jumping. I am simply having trouble on figuring out how to do this.

    @SubZeroGaming Thank you! I like interactive hands on learning its how i learned C++ (to a certain level) and C#. But I am aiming more for a 3D character controller but i will still see the series.
     
    Last edited: Aug 19, 2014
  5. RvBGames

    RvBGames

    Joined:
    Oct 22, 2013
    Posts:
    141
    @DSDX, Unity comes with the basic script for different controllers.

    3rdPersonController.png

    Do you know how to get to this? Or do you want to write your own?

    3rdPersonControllerImport.png

    This will add a Standard Assets folder, with the Character Controllers under it. The character controllers use JavaScript, but can be easily converted to C#. I would recommend starting with that.

    [EDIT] It's JavaScript not Boo (sorry).
     
  6. Death_Skull_DX

    Death_Skull_DX

    Joined:
    Aug 17, 2014
    Posts:
    7
    Oh yes i do know about the package but what i mean is i find it very difficult to create my own character controller without using premade scripts.
     
  7. RvBGames

    RvBGames

    Joined:
    Oct 22, 2013
    Posts:
    141
    Convert the JavaScript to C#. Then throw it away and rewrite another 10 times. Hopefully the rewrites will be getting done quicker and improved.

    Are you just having a problem with character controllers or other issues too?

    What about controlling the camera? This is a good, quick tutorial to look at:
    http://unitygems.com/quaternions-rotations-part-1-c/

    If you can be a little more specific, I might be able to help, or may know where you can find help.
     
  8. zDemonhunter99

    zDemonhunter99

    Joined:
    Apr 23, 2014
    Posts:
    478
  9. Moosetaco

    Moosetaco

    Joined:
    Jan 27, 2013
    Posts:
    77
    While doing the tutorials you should not just download the assets provided and plug them in but rather type out each script as you follow along. I found it extremely helpful to stop and look up everything within the API instead of blindly following the tutorial. After all that and you still draw a blank when writing a fresh script then you should probably start with a simple cube and get transform.translate to work. Slowly expand out from there.
     
  10. Death_Skull_DX

    Death_Skull_DX

    Joined:
    Aug 17, 2014
    Posts:
    7
    @coldjalapeno I am an active learner so i pretty much script as i watch and i pretty much look up at the manual to see if i get something or not so i did try that but still couldn't think how to do something completely on my own. If i don't get something then i play around with it or look for answers. Asking questions on forums is my last resort.

    @zDemonhunter99 Yes i did try to go through most which mattered to me though most of them were listed under the project tutorial which i visited as i was learning.

    @RvBGames No it's nothing to do with the character controller script it works correctly. Its mainly me trying to create my own version all by myself without copying or pasting code or without using a tutorial and not depending on using anything else other than the script API and an idea how i would execute what i want in code. This is mainly what i am having problems with. It was very difficult to express this issue that i have so apologies if it wasn't clear enough.
     
    Last edited: Aug 19, 2014
  11. Moosetaco

    Moosetaco

    Joined:
    Jan 27, 2013
    Posts:
    77
    If after playing with the editor and looking for answers hasn't worked then I'm not sure what kind of solution you expect to find from asking in the forums. All of the suggestions above is the only help folks can provide from a distance.

    If you think you retained everything you need then there should be minimal issues preventing you from starting. But if you are having problems with getting an object to move forward with mouse/keyboard button then you should either go back to some basic tutorials or start out with Transform
     
  12. Death_Skull_DX

    Death_Skull_DX

    Joined:
    Aug 17, 2014
    Posts:
    7
    Yeah i guess you are right. Its mainly figuring out what i have to find in the Script API for my scripts. For example say if i wanted to create a hit attack for my character with an animation. I wouldn't know where to look for it in the Script API. But thank you all for your help maybe i just have to go back and retry some things and it will probably click for me.
     
  13. kaiyum

    kaiyum

    Joined:
    Nov 25, 2012
    Posts:
    622
    I think you are all doing it wrong from the first place.
    In stead of doing game specific tutorial, you should learn unity engine's architecture first.

    Make sure, you know the followings, before going any further:
    [essential]
    1. How to create classes and use them.
    2. Why class is necessary, why can not we go with struct? And what is struct anyway? Why idea of struct is necessary, invented after all?
    3. Constructor and destructor. In C#, why is destructor not necessary to type in? Why in some case of unity c#, is constructor pointless?
    4. Access modifier(public-private-protected-internal) and their usage.
    5. How static variable affect editor and scripting and why indeed?
    6. Value type vs reference type, stack vs heap.
    7. Inheritance and function overloading.
    [/essential]


    However the following concept always helps, though not severe necessary.
    [secondary]
    1. Virtual machine.
    2. Managed vs Unmanaged.
    3. dot net c# vs unity c#
    4. Difference between dot net program execution vs unity c# program execution
    5. Encapsulation and polymorphism.
    6. Base-override-virtual-abstract, why these concepts are necessary.
    7. Why multiple inheritance is bad and thus absent in c#.
    8. Interfaces and its uses
    9. Delegates or pointer function. What are their relations with event-sendmessage()-mono behavior events?
    [/secondary]

    Those were language specific points we covered earlier. Now some very unity specific concepts, below.
    [unity essential]
    1. On a single object, in the context of a single script applied: Which runs after what? Which runs on how many times on single frame? Which run how many times on total gameplay?
    2. Co routines. Difference between coroutine and thread.
    3. What is the difference between "gameobject" and "component"(collider, physics2d, mesh renderer etc)? What is the similarities between them?
    4. Why does the engine look attached script as "component", not "gameobject"?
    5. Execution order of scripts. scriptRun.cs is applied on three object, scriptwalk.cs is applied on ten objects,.....such. Total number of unique applied scripts are 5: scriptRun.cs, scriptwalk.cs, scriptLove.cs, scriptKill.cs, scripFall.cs. Now which code will run after which?
    6. How to access gameobjects and components?
    7. What is the difference between update() and fixupdate()? why should we put physics related code in fixupdate()
    8. Why is most of the unity api monobehavior derived? What the heck is exactly monobehavior? Why can we not attach scripts which are not derived from mono?
    [/ unityessential]

    After finishing everything under "essential" tag, read straight from
    http://docs.unity3d.com/Manual/ScriptingSection.html
    to
    http://docs.unity3d.com/Manual/LogFiles.html
    Just do next-next-.....

    Then check unity gems for co routines and for question number 6 on "unity essential". In your pastimes, you can always read everything within "secondary" tag, add some popcorn with it. Delicious.

    Knock at forum, there are always good people out there to help you.
    Hope this helps.
     
    Ocid and Zeblote like this.
  14. KevinAristotle

    KevinAristotle

    Joined:
    Jun 25, 2013
    Posts:
    5
    Honestly, it sounds like you don't have enough programming experience in general. I had the same issues when trying to program a 2D game in XNA after only having a few months of programming experience. I simply couldn't go beyond the tutorials. So I revisited game programming after an entire year of general programming. That's when everything began to click. So I suggest you read the first half of a C# book, which will get you through all the main programming concepts. Then read a book on object oriented design. And finally a book on design patterns. After that, revisit game programming.

    Now I may be wrong in my above observations, so if you believe that to be the case, here's my other advice: experiment with making a first person game before tackling a third person game. First person is a lot simpler, and will help you familiarize yourself with the Unity API.

    Here's a link to a first person tutorial series that helped me out a lot:


    Once you're done with the tutorial series, create a simple first person exploration game that is driven by player interaction rather than combat. You shouldn't see the development of this game as a commercial endeavor, but rather as a way to familiarize yourself with Unity. Once you're done with that game, go ahead and tackle the game you truly want to make. Or maybe find a middle ground between the game you just made and your dream game. You can't start with your dream game because you don't have the skills to execute it yet. I personally am not going to start on my dream game for another 2 years. This is a journey. There are no shortcuts.

    Also here are some links to books I suggest reading:
    C# Programming (read first 7 chapters)
    http://www.amazon.com/5-0-Nutshell-The-Definitive-Reference/dp/1449320104/ref=sr_1_2?ie=UTF8&qid=1408490862&sr=8-2&keywords=c# programming

    Object Oriented Design
    http://www.amazon.com/Head-First-Object-Oriented-Analysis-Design/dp/0596008678/ref=sr_1_5?ie=UTF8&qid=1408491134&sr=8-5&keywords=object oriented programming

    Design Patterns
    http://www.amazon.com/Head-First-Design-Patterns-Freeman/dp/0596007124/ref=sr_1_2?ie=UTF8&qid=1408490992&sr=8-2&keywords=java head first
     
    kaiyum likes this.
  15. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    12,359
    I think the issue is with the problem solving skills rather than the technical ones, and the documentation won't help you there.

    A "hit attack with an animation" is unlikely to be explicitly documented, because it's not one engine feature, it's a bunch being used in tandem - there's input, there's collision, there's potentially physics, and there's animation. To know where to look in the docs to figure out how to implement that you first need to break the problem down into smaller parts, to the point where each part can be solved with a single tool. Then you look up how to use each of those tools, and you're on your way.

    Have you read the manual? That's a useful place to start. The tutes show you how to do things, but what you need is a general understanding of what tools are at your disposal. You'll need some level of familiarity with overall engine functionality so you can identify which parts of the engine are suited to solving what types of problems.
     
  16. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    12,359
    Also, this. Programming isn't something that's learned quickly. Yes, it's quick to learn how to write code, but writing code is only a small part of programming. I don't necessarily mean you should bugger off for a year, but it should be understood (I've said this many times before!) that game programming is a specialisation of programming, not a subset.
     
    KevinAristotle and kaiyum like this.
  17. Death_Skull_DX

    Death_Skull_DX

    Joined:
    Aug 17, 2014
    Posts:
    7
    @asngrypenguin That's why i said that i knew how the syntax works but creating a program or game is a whole different skill than just knowing the syntax and how functions,classes,coroutines and etc work. Its mainly trying to figure out how to piece things together and problem solivng which is the problem and i am planning to buy a design patterns and learn game programming with Unity to get used so that when I am used to with Unity 3D i can create something more complex. But other than that its more of a problem solving skill.

    @KevinAristole I do have quite a bit of programming experience with C++ doing console games and some Qt Apps. The reason i switched to Unity 3D was because i don't want to make a game engine with C++/use libraries with C++.

    I'd rather just jump in so I went to the fundamental C# course on Microsoft's Nine channel which was a hands on tutorial series which i spent 2 weeks on and i was using the MSDN reference and experimenting with the code i was using to know what it does correctly. Again the problem is nothing to do with the syntax and C# since i know it well enough its mainly trying to figure out which parts of the Scripting API i need to find to get my desired result. I am just so confused as to where to go in the Script API? Which function do i use?Do i have to use a special variable to use that function? How do i use this with this? It just gets so confusing and overwhelming i am simply left clueless as to what I have to.

    Also i am not making a dream game, that's shooting yourself on the foot. I am just trying to get used to Unity by doing simple projects. I wanted to make a script that just moves an object forward and backward, but when i look at the script API i don't where to go.

    Maybe i just need to try again and see what i missed out on.
     
  18. Ocid

    Ocid

    Joined:
    Feb 9, 2011
    Posts:
    476
    Great post.
     
  19. KevinAristotle

    KevinAristotle

    Joined:
    Jun 25, 2013
    Posts:
    5
    The best place to start when learning the Unity API is the MonoBehaviour class.
    http://docs.unity3d.com/ScriptReference/MonoBehaviour.html Every Unity script derives from this class. Attaching a script that derives from MonoBehaviour onto a scene object is what allows you to give the object gameplay related logic. So understanding how MonoBehaviour works, allows you to understand how Unity works at its most fundamental level.

    The next class you want to familiarize yourself with would be the Transform class . Every object in a scene has a transform, and everything related to that object can be accessed some way or another via the transform. http://docs.unity3d.com/ScriptReference/Transform.html Look at the inherited members and you'll see what I mean.

    And finally the 3 more classes that every Unity developer should know inside and out:
    http://docs.unity3d.com/ScriptReference/Vector3.html
    http://docs.unity3d.com/ScriptReference/Input.html
    http://docs.unity3d.com/ScriptReference/Time.html

    Learn those classes and let everything else branch out from there.
     
  20. Death_Skull_DX

    Death_Skull_DX

    Joined:
    Aug 17, 2014
    Posts:
    7
    Thanks, it would make more sense if i start there.
     
unityunity