Wednesday, February 3, 2010

Scripts

Scripts are basically files containing commands that tell Unity how certain objects should behave. One script you're familiar with already, is the one that allows us to walk around our game world in first person (the "FPSWalker" script). We are going to be using some other scripts as well that we will have to import, so that we could make our objects perform other actions, like rotate. To do this, we have to drag our script file into our 'Scripts' folder, that's inside our Standard Assets.

Now, to apply the script, either drag the script over to the object you want to attach it to, or select the object and go to "Component" > "Scripts" and select the script you want











One of the scripts that we are going to be using is called 'GemCollect;' this script lets us collect items (or 'gems') throughout our game a'la pacman or super mario. You should all have this script already included in your Scripts folder, so using one of the methods described above, attach the "GemCollect" script to your 'First Person Controller', this tells Unity that your character is able to collect certain objects. Next, to specify which objects are the ones that we can collect, we have to tag them. First select the object that you want to be collectible, then in the 'Inspector', click on the Tag attribute, and select 'gem.' If the tag 'gem' isn't already included, we're going to have to add it by selecting 'Add Tag...'.













This will take us to the Tag Manager; there, we will have to add the tag 'gem' to the first unused 'Element' in the list.







Once you have that done, just go back to the object you want to be collected, and select 'gem' from the Tag menu as described above. Repeat this for all your collectible objects.

No comments:

Post a Comment