Saturday, June 25, 2011

Item Collection in Unity3d game script


Well there is two ways to do it either using the OnControllerColliderHit
or By using a Trigger  


var cube_num = 0;
function OnControllerColliderHit(hit:ControllerColliderHit)
{
if(hit.gameObject.tag == "cube")
{

Debug.Log("Zam Gets a HoneyComb");
Destroy(hit.gameObject);
cube_num++;

}
}//END FUNCTION ONCONTROLLERCOLLIDERHIT

Using Trigger
var cube_num = 0;

function OnTriggerEnter(other: Collider) {
if (other.gameObject.tag == "cube") {
Destroy(other.gameObject);
cube_num++;
Debug.Log(honey_num);
}
}

No comments:

Post a Comment