예제 #1
0
    void OnCollisionEnter( Collision theCollision )
    {
        //Debug.Log("Collision");

        if(theCollision.gameObject.name == "floor" ||theCollision.gameObject.name == "fixe" || theCollision.gameObject.tag == "platform" )
        {
            gravity = gestion.gravityState;

            ColliderCote[] tempColliders;

            if ( colliders == null || colliders.Length < 1 )
                tempColliders = new ColliderCote[1];
            else
            {
                tempColliders = new ColliderCote[ colliders.Length + 1 ];
                for( int j = 0; j < colliders.Length; j++)
                    tempColliders[j] = colliders[j];
            }
            colliders = tempColliders;

            bool setBas, setHaut, setGauche, setDroite;

            float posY = transform.position.y + transform.localScale.y / 2 - theCollision.gameObject.transform.position.y + theCollision.gameObject.transform.localScale.y / 2;
            if( posY >= 0 && posY < seuil ) {
                setBas = true;
            } else
                setBas = false;
            posY -= transform.localScale.y + theCollision.gameObject.transform.localScale.y;
            if( posY <= 0 && posY > -seuil ) {
                setHaut = true;
            } else
                setHaut = false;

            float posX = transform.position.x + transform.localScale.x / 2 - theCollision.gameObject.transform.position.x + theCollision.gameObject.transform.localScale.x / 2;
            if( posX <= 0 && posX > -seuil ) {
                setGauche = true;
            } else
                setGauche = false;
            posX -= transform.localScale.x + theCollision.gameObject.transform.localScale.x;

            if( posX >= 0 && posX < seuil ) {
                setDroite = true;
            } else
                setDroite = false;

            //Cote theCote = gestion.CoteWithGravity( new Cote( 0, setHaut, setBas, setGauche, setDroite) );
            Cote theCote = new Cote( 0, setHaut, setBas, setGauche, setDroite );
            //Debug.Log( theCote.ToString()  );
            colliders[ colliders.Length - 1 ] = new ColliderCote( theCollision.gameObject, theCote );
            gestion.Add( theCote );

            /*
            if( colliders.Length == 0 )
                Debug.Log( "Collisions ="+colliders.Length );
            if( colliders.Length == 1 )
                Debug.Log( "Collisions ="+colliders.Length + " " + colliders[0].gameObject.name );
            if( colliders.Length == 2 )
                Debug.Log( "Collisions ="+colliders.Length + " " + colliders[0].gameObject.name + " " + colliders[1].gameObject.name );
            if( colliders.Length >= 3 )
                Debug.Log( "Collisions ="+colliders.Length + " " + colliders[0].gameObject.name + " " + colliders[1].gameObject.name + " " + colliders[2].gameObject.name );
                */
        } else if( theCollision.gameObject.tag == "ennemi" ) {
            transform.position = spawn;
            gestion.stopped = false;
        }
    }
예제 #2
0
    //consider when character is jumping .. it will exit collision.
    void OnCollisionExit( Collision theCollision )
    {
        //Debug.Log("CollisionExit");
        if(theCollision.gameObject.name == "floor" ||theCollision.gameObject.name == "fixe" || theCollision.gameObject.tag == "platform" )
        {
            ColliderCote[] CollidersTemp = null;

            for( int i = 0; i < colliders.Length; i++ ) {
                ColliderCote collider = colliders[i];
                if( theCollision.gameObject == collider.gameObject ) {
                    gestion.Substract( collider.cote );
                    CollidersTemp = new ColliderCote[colliders.Length - 1];
                    int nb = 0;
                    for( int j = 0; j < colliders.Length; j++ ) {
                        if( j != i ) {
                            CollidersTemp[nb] = colliders[j];
                            nb++;
                        }
                    }

                }
            }
            if( CollidersTemp != null ) {
                colliders = CollidersTemp;
            }
            //Debug.Log( "Collisions ="+colliders.Length );
        }
    }