I've got a box & piece of terrain called "Area1grass". The box has a 2d box collider & the terrain has a 2d polygon collider. Both colliders are set to be triggers.
This script below moves the box left & right using the arrow keys, it moves down automatically 0.019 & is supposed to move up by 0.02 when it collides with the terrain {it warps back to the top if it goes too far down}. It's just a simple test to become familiar with colliders:
#pragma strict
function Start () {
}
function Update () {
if(Input.GetKey ("left")){
transform.position.x = transform.position.x -0.1;
} if(Input.GetKey ("right")){
transform.position.x = transform.position.x + 0.1;
}
transform.position.y = transform.position.y - 0.019;
if(transform.position.y < (-5)){
transform.position.y = 6;
}
}
function OnCollisionEnter(collider : Collider){
if(collider.gameObject.tag == "Area1grass"){
transform.position.y = transform.position.y + 0.02;
}
}
Everything else is running just fine except that the box falls through the terrain every time, I've been through countless questions/answers on here & none of them seem to work >.>
Remember I'm not using rigidbodies or Unity's built in physics; I simply want to know how to detect when one gameObject is touching another.
Any help is much appreciated ^-^
↧