Archive for the ‘Tutorials’ Category

Networking in Unity3D

Posted: March 4, 2011 in Tutorials

Hi again!

In this tutorial I’m going to show you how to make a networking virtual Environment with unity 3D.

Script Download Link.

Unity Package Download Link.

UnityPackage Download (Link#2) – for those who cannot download from 4shared

Hope you like it and stay tuned for more and more tutorials on this amazing software.

Thanks for visiting my website.

Hi again! this tutorial is for the software unity3D and it let you interact with the door and the key in the scene. in here we will teach:

if you pick up the key you can open the door by pressing “E” button (with the GUI alert to inform the player) and if you don’t have the key you cannot open the door and it will be the GUI come out tell you to collect the key.

You can download the whole unity package that I test on it from here and see the process. (It is package so just import it to one unity file and use it as package).

1- Create necessary objects for your scene which you want to open the door with and etc.What I created here is a “Cylinder (as a key)”, “2 Cube (1 for door and the other one for floor)”, “first person controller (As a player)” and one light.

2- Select your door and create an empty object and call it as door.

3- Select that empty object and make the “Box Collider” with it. (Components> Physics> Box Collider) and adjust the size of the trigger bigger than the door itself. And make the door children of this empty game Object. (drag the cube of the door and drop it to that empty game object)

4- Select your key and after making the “Key” tag from tag manager, assign it to the key object.(Edit> Project setting> Tags)

5- Select your key and make sure that it has a collider and it’s selected already.

6- Make one Empty object on your key or anywhere in the scene for assigning the GUI Script on it. Start scripting on your GUI it means that this GUI when you get the key it will be activated and this GUI of the key will appear. It has one static var because we want to call it after we picked up the key not whenever we can see it. And it has one var of texture 2D which allow us to assign the chosen picture for the key. Name your script “GUIKey” and assign it to that empty game object.

7- Assign the key vector or any GUI picture that you have chosen by drag and drop it in the inspector panel.

8- Alright, In here we will start scripting on our door. In function update we will say how the door must open and close. And in the function of “OnTriggerEnter” or “OnTriggerExit” we will define the variables which must be true or not. As you can see we called our previous script with its static variable from here. Also we must make another script for the door that if its enter the trigger it will say that press E to open the door or if you don’t have the key go and find the key. This one you can see it in the next step (Step 9).

9- Alright in this step you know what we want to do; we want to make the script for alerting the GUI and make it something like alert. As you saw in previous script we defined another static variable which we are calling it from this script to show the script in the right and exact time. Also I made a print then you can see it from here what the process is and what we are doing.

10- Alright in this step we want to make the script that if the player get the key the GUI that we defined first appear and also he can open the door with it. And also destroy the key. We used our two static variables here and connect our script to another 2 scripts. (assign it to your Player)

11- Don’t forget to tag your first person controller, user or anything as “Player” the player tag does already exist there. Because we told in the script if an object with the tag of “Player” enter the trigger do anything so if you don’t pay enough attention to the tags those scripts won’t run as well.

12- In this step we will assign the scripts that we did before to the objects that we need. We will assign that script of alert for press E or anything with the script of opening the door to the empty game object of the door which that door is the children of it. (Don’t assign the scripts to the door itself; assign them to the empty game object which is the parent of the main door). Also make sure that the numbers of smooth and door open Y in the inspector panel is not 0.

13- Play the game and enjoy it!

P.S: I made those scripts just for opening the door so for close the door also you can make the script that if the player go out of the trigger bring the door to the first position.

You can download the whole unity package that I test on it from here and see the process. (It is package so just import it to one unity file and use it as package).

Unity3D Health system

Posted: March 2, 2011 in Tutorials

This is the video tutorial on how we can do the health system in Unity3D.

How to make health system in Unity3D – part1

How to make health system in Unity3D – part2

How to make health system in Unity3D – part3

the actual script:

the script which has the name of “Player” and it must assign to the Player (old First Person Controller!):

Download Link

Second Script which must assign to the object that if player go near the object it will get hit and deduct from HEALTH variable:

Download Link

1st step: Draw you terrain in unity.

2nd step:  In the menu bar under the “Terrain Menu” Select” Export Height map”.

3rd step: In Export heightmap menu options select 8 bit and if you are working with windows change the ByteOrder to windows. And press EXPORT.

4th Step: Then the software automatically asks you where you want to save the file, and you must choose the directory.

5th step: Then Open the Adobe Photoshop and drag
and drop the file that you exported to Photoshop and convert it to jpeg. Set the
setting like what I’ve shown in the picture below.

6th step: Then open the 3D max software and draw
a plane (Same size with what you’ve drawn in Unity). By default unity sets your
terrain to 2000*2000 with the height of 600. You can see your terrain
specification in set resolution under terrain menu in unity. So I will draw a
plane 2000*2000 here. And set your length segments and height segments to 300.
(Maximum is 300, you can choose 100 even, but your terrain quality won’t be
shown as good quality)

7th step: Apply the modifier “Displace” from modifier
list to your plane. And change its strength in the modifier options to 600.

8th step: In the Image bitmap menu in displace modifier
click on NONE button and choose your Jpeg heightmap which you exported from Photoshop.

9th step:   There we go; we have our unity terrain in our
3d max.

How to paint your 3D max terrain and import it to unity3d

1st step:Select your 3D terrain in 3d max and convert it to editable
poly. (if you want to know how you can import your unity3d terrain in 3d max click
here
).

2nd step:Apply the modifier called (Unwrap UVW) to the object in the
scene.

3rd step: Open the UV editor from the Unwrap UVW modifier options.

4th step: Make sure you select the polygons on the UV editor panel.

5th step: In the mapping menu select the Flatten mapping.

6th step: Change the spacing of the UV unwraps to 0.

7th step: Export your 3D max terrain to FBX. (if you don’t have FBX
exporter click here to download it).

8th step: Open the Autodesk Mudbox 2012 and import your saved FBX
file.

9th step: At the bottom left select projection paint tool and at the
right side of it select stencil.

10th step: Create the new painting layer in TIFF, 8 bit color.

11th step: Click on your selection stencil and start painting your
terrain, if you want to be faster for painting select use tiles from the menu of
the stencil options.

12th step: You can choose multiple stencils to paint your terrain as
well.

13th step: After you finished painting your terrain, you must export it
to 3d max. Mudbox 2012 has this ability to compile everything and import it
directly to the 3d max.

14th step: Now you have your terrain painted in your 3d max.

15th step: Press “M” on your keyboard in 3d max to bring the material
editor and find the location of the map which mudbox created already. (you can
also export your map from mudbox).

Export your terrain which you painted already as FBX again.

16th step: Open unity and import your 3d terrain with its map together.

17th step: In the right menu under inspector you can find your
terrain’s detail. You can see what kind of texture it has and so on.

18th step: There we go! We have our terrain painted and complete in
Unity.