Wednesday 2 May 2012

Scripting revision..

Having used javascript to a degree in my previous projects I was fairly familiar with how I wanted the game to work. I looked back at my previous scripts and decided I would have to add additional scripts. I decided to review the unity website for reference.

The tag system built into unity allows me to tag an object with a label, to allow me to reference them through the scripts.
An example of the player tag being assigned to a game object:

Colliders are used to detect when objects collide. They can be applied in variety of shapes, from boxes, spheres, capsules or even to a mesh of an object. I used these in previous projects mainly for the combat system. A typical scenario would involve two colliders colliding to trigger the health of the player to decrease, or increase when collided with a med kit. This will be used for our combat and health system, but without the scripts these functions will do nothing.
An example of a mesh collider being added to the scene geometry:


Collider.OnTriggerEnter is needed in the script to detect the collision of the collider attached to the enemy. Here is Unity's reference to the code:
 CharacterController.OnControllerColliderHit is used on the player as it uses a character controller to move the character around the scene. Here is Unity's reference to the code:




No comments:

Post a Comment