Wednesday, October 24, 2012

First Person Shooter and Third Person Shooter with Unity3D

Ok, So Today I have learned how to build a simple game using Unity3D

1. First Person Shooter

step1: create a new project -> import Character Controller.unityPackage and also Scripts.unityPackage
step2: create a floor (GameObject -> Create Other -> Plane)
step3: create a light (GameObject -> Create Other -> point light)
step4: on middle bottom, search for "first Person Controller", drag into left hand side(make sure it is on top of the plane)
step5: hit the run button on middle top and you can control your character to move around the floor


2. Third Person Shooter


step1: create a new project -> import Character Controller.unityPackage and also Scripts.unityPackage
step2: create a floor (GameObject -> Create Other -> Plane)
step3: create a light (GameObject -> Create Other -> point light)
step4: create your character( GameObject -> Create Other -> sphere)
step5: make sure you highlight your character(Sphere) then click Component-> Physic->Character Controller
step6: right click on bottom middle create new Javascript
step7: double click open your javascript and paste in the following code


var speed = 3.0;
var rotateSpeed=3.0;


function Start () {

}

function Update () 
{
var controller : CharacterController = GetComponent(CharacterController);
transform.Rotate(0,Input.GetAxis("Horizontal")*rotateSpeed,0);
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed=speed * Input.GetAxis("Vertical");
controller.SimpleMove(forward * curSpeed);


}

@script RequireComponent(CharacterController)




step 8: drag your javascript into the Sphere (you can now hit play and control your sphere)
step 9: To make the camera following your sphere, you need to search for "smooth follow" on middle bottom
step10: drag the smooth follow script into your main camera on the left
step11: drag the sphere into the your main camera smooth follow "target"
step12: run the game and you can control your sphere to move around the floor and the camera is following


Hope it help



No comments:

Post a Comment