예제 #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        boxCollider.bounds.GetTopLeft(ref start);
        boxCollider.bounds.GetBottomLeft(ref end);
        left = ParallelCast(hits, start, end, 1, numCastsVertical);

        boxCollider.bounds.GetTopRight(ref start);
        boxCollider.bounds.GetBottomRight(ref end);
        right = ParallelCast(hits, start, end, -1, numCastsVertical);

        boxCollider.bounds.GetTopLeft(ref start);
        boxCollider.bounds.GetTopRight(ref end);
        top = ParallelCast(hits, start, end, -1, numCastsHorizontal);

        boxCollider.bounds.GetBottomLeft(ref start);
        boxCollider.bounds.GetBottomRight(ref end);
        grounded = ParallelCast(hits, start, end, 1, numCastsHorizontal);

        currentState.Execute(this);
    }
예제 #2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (facing == Direction.Left && spriteRenderer.flipX == false)
        {
            spriteRenderer.flipX = true;
        }
        else if (facing == Direction.Right && spriteRenderer.flipX == true)
        {
            spriteRenderer.flipX = false;
        }

        boxCollider.bounds.GetTopLeft(ref start);
        boxCollider.bounds.GetBottomLeft(ref end);
        left = ParallelCast(hits, start, end, 1, numCastsVertical);

        boxCollider.bounds.GetTopRight(ref start);
        boxCollider.bounds.GetBottomRight(ref end);
        right = ParallelCast(hits, start, end, -1, numCastsVertical);

        boxCollider.bounds.GetTopLeft(ref start);
        boxCollider.bounds.GetTopRight(ref end);
        top = ParallelCast(hits, start, end, -1, numCastsHorizontal);

        boxCollider.bounds.GetBottomLeft(ref start);
        boxCollider.bounds.GetBottomRight(ref end);
        bottomHit = ParallelCast(hits, start, end, 1, numCastsHorizontal);

        if (bottomHit)
        {
            levelgrid.CompareScenePositions(bottomHit.collider.gameObject.scene.buildIndex);
            canDash = true;
        }

        currentState.Execute(this);
        if (debug)
        {
            GetComponent <MeshRenderer>().material.color = currentState.DebugColor;
        }

        if (rigidbody2d.velocity.x != 0)
        {
            facing = rigidbody2d.velocity.x > 0 ? Direction.Right : Direction.Left;
        }

        if (Input.GetKey(KeyCode.Mouse0))
        {
            animator.SetBool("Attack", true);
            Vector2 direction = facing == Direction.Left ? Vector2.left : Vector2.right;

            Debug.DrawRay(rigidbody2d.position, direction * maxAttackDistance, Color.red);

            RaycastHit2D[] hits = Physics2D.BoxCastAll(rigidbody2d.position, attackBoxSize, 0, direction, maxAttackDistance, attackLayerMask);

            foreach (RaycastHit2D hit in hits)
            {
                //maintain a list of objects that can be attacked in a scriptable object?
                //using:
                //hit.collider.GetInstanceID()
                //and a scriptable object?
                BreakableTileInstance bti = hit.collider.GetComponent <BreakableTileInstance>();
                if (bti == null || bti.spriteRenderer.sprite != bti.tileRef.sprites[0])
                {
                    continue;
                }

                bti.StartCoroutine(bti.BreakTile());
            }
        }
    }