Can someone show me how to detect collisions in Javascript? like, “if this touches this than do this” kind of thing.
If you’re using a collider:
function OnCollisionEnter(collision : Collision)
{
if(collision.gameObject.name == "ThatOneObject") // Or collision.gameObject.tag
{
// Do something
}
}
There is also:
OnCollisionExit and OnCollisionStay
If you’re using isTrigger:
function OnTriggerEnter(collider: Collider)
{
if(collider.gameObject.name == "ThatOneObject") // Or collider.gameObject.tag
{
// Do something
}
}
There is also OnTriggerExit and OnTriggerStay.
Thanks a lot.