Where can I find Unity Script Tutorials that teach how to make the scripts come together?

I have been looking around for a long time at various tutorials to teach me Unity Script, and have had great deal of luck every time I am looking for a specific solution to a specific problem Im having. I would still call myself a beginner with scripting and I’ve been having a lot of problems finding help from online tutorials that gets me past the initial steps of learning to script. I’m having trouble thinking of a good way to explain my problems, but here goes:

The first book I got a long time ago when I was learning ActionScript for Flash said that using OOP was like building all the pieces that were needed for an airplane, and then putting them together. To make the landing gear, you need to write the wheel, the wheel socket, the brakes and the part that connects them all to the plane. I understand how to script all the parts fairly well, but I am having trouble figuring out how to fit them together and make them interact effectively with one another.

I know a need a main systems script that I assume will not be attached to any GameObject, but I do not know how to call from it when using scripts attached to game objects in the scene. I am trying to create an old school JRPG and I am thinking that I will need to create at least 4 game modes at the top level, a normal mode where I wander around and interact with objects and NPCs, and event mode where everything is paused but animations of specific characters and items I am interacting with, a menu mode that pulls up the game menu with all the stats and items and equipment and whatnot, and a battle mode where fighting takes place.

My question for this instance is where are these game mode scripts located, how do I access them with other scripts and what types of scripts should I be using? I am not very experienced in creating classes and utilizing them with other scripts, should I create these scripts as classes? I’m thinking my questions are more related to creating the basic systems scripts, and as I said, I am having a lot of trouble finding tutorials that go over the way to build a network of scripts that work together behind the scenes. If anyone could point me in the right direction to a tutorial, or give me some simple explanation (Im doubting this exists) that will set me on the right path it would be very helpful.

I can give one more example of something Im having trouble figuring out how to put together, an inventory that lets you pick up items. I know I could create a class that would be for items that would have variables for the name, an image and description of what it does, then make sub classes that extend with functions (healing item, equipment, key item etc.) that tell the items to heal or add stats or what not, but Im not sure if I can then just push those scripts into an array that tells the number of that item you have for the inventory or if I have to instantiate the object for each time its collected. Also how to call that item in another script, for example would it be potion.HealingItem.Item(use) or leathervest.Equipment.Item(equip), or whatever.

I am also thinking having separate scripts that outline the functions an item could do that would call on variables within the items scripts should be the way to go. For example make a script for healing that would add x amount of hp to a target, an antidote that would turn a poison effect from true to false, or do nothing if it was false already. That way I could call these scripts and use them for abilities as well. How would I call on these functions from different scripts in the item script? Would I have to make all these functions in a class script? Or do I have to write these into the item script for each item every time?

A tutorial on how to make all that work would be really helpful as well.

I understand how to attach a script to a GameObject, and how to make GameObjects interact with each other, but the problem Im having is attaching scripts to other scripts and making them interact with each other.

I know the questions are vague and likely have multiple answers, so I guess I need vague answers on the bigger picture, making the pieces of Unity Script work together, not just how to make specific scripts do specific things. Again, any help or nudges in the right direction would be greatly appreciated.

edit: Forgot to mention I am using Javascript to code.

A’ight:

In Unityscript (“javascript”), you can create classes like this:

class X extends Y { /stuff/ }

If you don’t have a “class X” line anywhere in the file, Unity assumes that the first line of the file is this:

class filename extends MonoBehaviour {

And of course it closes the bracket for you.

In C# you -must- include the class declaration line(s) yourself.

So - all your JS files are classes. You don’t (and can’t) have anything that’s “just a script but not a class”. Hopefully that helps clear some confusion away.

GetComponent returns a Component. MonoBehaviour is descended from Component. So if your class extends MonoBehaviour, you should use GetComponent (or another method of acquiring a specific Behaviour) to get it, and use AddComponent to add it to an object.

Say X extends MonoBehaviour (“is a component”), and you want the X off a specific GameObject Y: you’d use “myX = Y.GetComponent(X)”, “myX = Y.GetComponent.()” (fastest), or “myX = Y.GetComponent(“X”)” (slowest).

If X does NOT have MonoBehaviour as an ancestor, then it’s a non-component class, and you need to use ‘new’ to create it: “myX = new X()”.

C# has a bit more punch to it at times. On the forum there are several extensive tests done on performance speed; for the most part, all three languages run at the same speed. They’re compiled, after all. Off the top of my head, C# gives you much finer control over function arguments, like the ref keyword and delegates and such. I have a few C# classes in my mostly-JS project just to handle generics/refs and there’s no issues. Use what you’re comfortable with, and if you come up against a wall, consider using another language for that specific issue.

Last, “manager”-type classes are often static. For example, I usually have a “Game” class that handles stuff like level loading and game-over. The Game keeps track of important objects, but everything else runs independently of other objects, reacting to collisions or Game messages rather than trying to seek out specific objects and create long dependency chains outside their parent-child relationships.

here you can find a tutorial on script interaction and also other topics unitygems.com - unitygems Resources and Information.