Esempio n. 1
0
 private void OnCollisionStay2D(Collision2D collision)
 {
     if (
         collision.gameObject.CompareTag("Platform") &&
         CollisionUtilities.GetCollisionPosition(collision) == CollisionUtilities.CollisionPosition.BOTTOM &&
         CollisionUtilities.FullyContactingPlatform(collision.collider.bounds, this.playerCollider.bounds, 0.25f)
         )
     {
         if (collision.collider != this.lastPlatformCollider)
         {
             this.lastPlatformCollider = collision.collider;
         }
         this.lastOffset = this.transform.position - this.lastPlatformCollider.bounds.center;
     }
 }
    private void FixedUpdate()
    {
        if (this.platformCollider != null)
        {
            if (!CollisionUtilities.FullyContactingPlatform(this.platformCollider.bounds, this.enemyCollider.bounds, 0f))
            {
                this.direction *= -1;
            }

            this.enemyOffset     += Vector3.right * this.direction * Time.deltaTime;
            this.enemyRB.position = this.platformCollider.bounds.center + this.enemyOffset;
        }
        else if (this.dead)
        {
            Vector3 positionInViewport = UnityEngine.Camera.main.WorldToViewportPoint(this.enemyRB.position);
            if (!new Rect(0, 0, 1, 1).Contains(positionInViewport))
            {
                Object.Destroy(this.gameObject);
            }
        }
    }