- Home /
Question by
karl_ · Mar 11, 2010 at 11:24 PM ·
collisiongameobjectpickup
Collection Script troubles
In this script we are trying to collect items on collision. So far it is not working. It will not update the gameObject but it is recognizing the hit in the debug log.
var honey_num = 0;
function OnControllerColliderHit(hit:ControllerColliderHit)
{
if(hit.gameObject.tag == "honey_gold")
{
//Get the Honey Counter Object
//var honey_counter = GameObject.Find("HoneyCount");
Debug.Log("Zam Gets a HoneyComb");
Destroy(hit.gameObject);
honey_num++;
//honey_counter.gameObject.GUIText.Text = honey_num;
}
}//END FUNCTION ONCONTROLLERCOLLIDERHIT
Comment
Best Answer
Answer by Lipis · Mar 12, 2010 at 11:04 AM
This should work maybe we need more info on what exactly is not updating.
Since you are collecting items though, it's better to use triggers. If you want to try it, on your Collider
component set the Is Trigger
to true
and use the OnTriggerEnter()
instead, like:
var honey_num = 0;
function OnTriggerEnter(other: Collider) {
if (other.gameObject.tag == "honey_gold") {
Destroy(other.gameObject);
honey_num++;
Debug.Log(honey_num);
}
}
Aha! Perfect. We had IsTrigger marked when using the collider script. Once switching to OnTriggerEnter everything worked great.
Thanks a bunch.
FYI.. If you remove the IsTrigger the OnControllerColliderHit() will work!