Esempio n. 1
0
        private void FixedUpdate()
        {
            if (!m_can_damage)
            {
                return;
            }

            Vector2 scale = m_transform.lossyScale;

            Vector2 facingOffset = Vector2.Scale(offset, scale);

            if (m_sprite_renderer != null && m_sprite_renderer.flipX != m_origin_flip)
            {
                facingOffset = new Vector2(-offset.x * scale.x, offset.y * scale.y);
            }

            Vector2 scaledSize = Vector2.Scale(size, scale);

            Vector2 pointA = (Vector2)m_transform.position + facingOffset - scaledSize * 0.5f;
            Vector2 pointB = pointA + scaledSize;

            Array.Clear(m_hits, 0, m_hits.Length);
            int hitCount = Physics2D.OverlapAreaNonAlloc(pointA, pointB, m_hits, hittable_layers);

            for (int i = 0; i < hitCount; i++)
            {
                /// TODO : 몬스터 스크립트 가져와서 데미지 주는거 추가해야함
                float calcHp = m_hits[i].GetComponent <CharacterComponent>().unit.rank.current_hp -
                               m_character.unit.rank.damage;
                m_hits[i].GetComponent <CharacterComponent>().unit.rank.SetCurrentHp(calcHp);
            }

            m_can_damage = false;
        }
Esempio n. 2
0
    void BallCollision(Collision2D coll)
    {
        Vector2 pointA, pointB;

        pointA = new Vector2(transform.position.x, transform.position.y);
        pointB = new Vector2(transform.position.x, transform.position.y);

        pointA.x += velocity.x / speed / Time.fixedDeltaTime;
        pointA.y += velocity.y / speed / Time.fixedDeltaTime;

        pointB.x -= velocity.x / speed / Time.fixedDeltaTime;
        pointB.y += velocity.y / speed / Time.fixedDeltaTime;

        GameObject a = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        GameObject b = GameObject.CreatePrimitive(PrimitiveType.Sphere);

        a.transform.position = pointA;
        b.transform.position = pointB;

        int layerID   = LayerMask.NameToLayer("Tetroid");        // 0-31
        int layerMask = 1 << layerID;

        layerID   = LayerMask.NameToLayer("Tetris");
        layerMask = layerMask | 1 << layerID;
        int num = Physics2D.OverlapAreaNonAlloc(pointA, pointB, colliders, layerMask);

        Debug.LogError("");
        //Destroy (a);
        //Destroy (b);
    }
Esempio n. 3
0
    void Update()
    {
        ClearPoints();
        int counts = Physics2D.OverlapAreaNonAlloc(leftP, right.position, cs, layer);

        HitToSetPoints(cs, counts);
    }
Esempio n. 4
0
    // Update is called once per frame
    void Update()
    {
        if (IsOn)
        {
            int          isAnyCollision = 0;
            Collider2D[] collider       = new Collider2D[2];
            switch (colliderCheckerType)
            {
            case ColliderCheckerType.RectangleArea:

                //metoda nie alokuje pamieci, bierze tylko to co jej dalismy (wychodzi na to, ze zwracany wynik tez jest zalezny od tej tablicy
                //jaka mu przekazemy, pewnie zwraca cos w rodzaju array.Length
                isAnyCollision = Physics2D.OverlapAreaNonAlloc(_UpperLeftCorner, _LowerRightCorner, collider, 1 << this.gameObject.layer);

                break;

            case ColliderCheckerType.CircleArea:
                isAnyCollision = Physics2D.OverlapCircleNonAlloc(collider2D.renderer.bounds.center, collider2D.renderer.bounds.size.x / 2, null, 1 << this.gameObject.layer);
                break;

            default:
                return;
            }
            //na to wyglada, ze on sam siebie tez bierze pod uwage O.o
            if (isAnyCollision > 1)
            {
                isAnyCollision = 0;
                _scriptStartInterface.StartInterface();
            }
            PreviousPosition = transform.position; //rozwiazanie troche na skroty, ale w tym momencie chyba najlepsze :D
                                                   //inaczej bym musial sie dostawac do wszystkich elementow, z ktorym obiekt ma kolizje
                                                   //i wyznaczac dokladniejsza pozycje
        }
    }
Esempio n. 5
0
        Rigidbody2D GetBodyAtTouch(ref InputInfo info)
        {
            // Make a box
            var lowerBound = new Vector2(info.worldPosition.x - info.worldDistance, info.worldPosition.y - info.worldDistance);
            var upperBound = new Vector2(info.worldPosition.x + info.worldDistance, info.worldPosition.y + info.worldDistance);

            Rigidbody2D body = null;

            // Query the world for overlapping shapes
            int queryCount =
                Physics2D.OverlapAreaNonAlloc(
                    lowerBound,
                    upperBound,
                    m_QueryColliders,
                    m_EnabledOnLayers);

            for (int i = 0; i < queryCount; ++i)
            {
                body = m_QueryColliders[i].attachedRigidbody;

                if (body)
                {
                    break;
                }
            }

            return(body);
        }
Esempio n. 6
0
    protected override void FixedUpdate()
    {
        base.FixedUpdate();

        var pos = (Vector2)transform.position;

        var wasGrounded = isGrounded;

        isGrounded = Physics2D.OverlapAreaNonAlloc(pos + feetA, pos + feetB, dumbColliders, groundLayers) > 0;

        if (isGrounded)
        {
            transform.parent = dumbColliders[0].transform;
        }
        else
        {
            transform.parent = null;
        }

        var mirror = new Vector2(-1, 1);

        var isGrippingRight = Physics2D.OverlapAreaNonAlloc(pos + handA, pos + handB, dumbColliders, groundLayers) > 0;
        var isGrippingLeft  = Physics2D.OverlapAreaNonAlloc(pos + Vector2.Scale(handA, mirror), pos + Vector2.Scale(handB, mirror), dumbColliders, groundLayers) > 0;

        if (isGrounded && RemainingJumps > 0)
        {
            canAirJump = true;
        }

        var horizontal = Input.GetAxis("Horizontal");

        if (isGrippingRight)
        {
            horizontal = Mathf.Clamp(horizontal, float.NegativeInfinity, 0);
        }

        if (isGrippingLeft)
        {
            horizontal = Mathf.Clamp(horizontal, 0, float.PositiveInfinity);
        }

        var sign = Mathf.Sign(horizontal);

        animator.SetBool("Mirror", sign < 0);
        animator.SetBool("IsWalking", Mathf.Abs(horizontal) > 0.3f);
        animator.SetBool("IsGrounded", isGrounded);
        animator.SetFloat("Vertical Speed", rigidbody2D.velocity.y);
        landSpeed = Mathf.Min(rigidbody2D.velocity.y, landSpeed);

        if (isGrounded && !wasGrounded)
        {
            animator.SetFloat("Land Speed", landSpeed);
            landSpeed = 0;

            // Reset Remaining Jumps
            RemainingJumps = TotalJumps;
        }

        rigidbody2D.velocity = new Vector2(horizontal * speed, rigidbody2D.velocity.y);
    }
Esempio n. 7
0
    /// <summary>
    /// check colliders if exist it use movetargetline on this object
    /// return possibilty to move object in the direction
    /// </summary>
    protected void moveSideElements(bool toRight)
    {
        int layer = gameObject.layer;

        gameObject.layer = 1;
        if (toRight)
        {
            pushCollision = Physics2D.OverlapAreaNonAlloc(
                new Vector2(transform.position.x - sideRadius + width / 2, transform.position.y + width / 2 - 0.1f),
                new Vector2(transform.position.x + sideRadius + width / 2, transform.position.y - width / 2 + 0.1f),
                pushColliders, whatIsMoveable);
        }
        else
        {
            pushCollision = Physics2D.OverlapAreaNonAlloc(
                new Vector2(transform.position.x - sideRadius - width / 2, transform.position.y + width / 2 - 0.1f),
                new Vector2(transform.position.x + sideRadius - width / 2, transform.position.y - width / 2 + 0.1f),
                pushColliders, whatIsMoveable);
        }
        gameObject.layer = layer;

        for (int i = 0; i < pushCollision; i++)
        {
            pushColliders[i].GetComponent <VerticalLines>().MoveTargetLine(toRight);
        }
        return;
    }
Esempio n. 8
0
    void CheckWeight()
    {
        Collider2D[] _weightsArray = new Collider2D[10];
        Physics2D.OverlapAreaNonAlloc(collider2D.bounds.max, collider2D.bounds.min, _weightsArray);

        currWeight = 0;
        foreach (Collider2D col in _weightsArray)
        {
            if (col != null)
            {
                if (col.gameObject.layer == 11 && GameObject.FindObjectOfType <Telekinesis>().heldObj != col.gameObject)
                {
                    currWeight += col.GetComponent <Weight>().weight;
                }
                if (col.gameObject.tag == "Player")
                {
                    currWeight += col.transform.GetComponent <Weight>().weight;
                }
            }
        }

        _normalWeight = currWeight / maxWeight;                                                                 //get normailzed weight value
        _normalWeight = 1 - _normalWeight;                                                                      //invert value to match scale
        _targetHeight = (_minHeight + (_normalWeight * (_maxHeight - _minHeight)));                             //set Target height to normal value, realsied in worldSpace
    }
Esempio n. 9
0
    void CheckScales()
    {
        Collider2D[] weights1 = new Collider2D[10];
        Physics2D.OverlapAreaNonAlloc(weight1.collider2D.bounds.max, weight1.collider2D.bounds.min, weights1);
        currWeight1 = 0;

        foreach (Collider2D col in weights1)
        {
            if (col != null)
            {
                if (col.gameObject.layer == 11 && GameObject.FindObjectOfType <Telekinesis>().heldObj != col.gameObject)
                {
                    currWeight1 += col.GetComponent <Weight>().weight;
                }
                if (col.tag == "Player")
                {
                    currWeight1 += col.transform.GetComponent <Weight>().weight;
                }
            }
        }

        Collider2D[] weights2 = new Collider2D[10];
        Physics2D.OverlapAreaNonAlloc(weight2.collider2D.bounds.max, weight2.collider2D.bounds.min, weights2);
        currWeight2 = 0;

        foreach (Collider2D col in weights2)
        {
            if (col != null)
            {
                if (col.gameObject.layer == 11 && GameObject.FindObjectOfType <Telekinesis>().heldObj != col.gameObject)
                {
                    currWeight2 += col.GetComponent <Weight>().weight;
                }
                if (col.tag == "Player")
                {
                    currWeight2 += col.transform.GetComponent <Weight>().weight;
                }
            }
        }

        currFullWeight = 0;
        currFullWeight = currWeight1 + currWeight2;                     //Set current weight of both scales combined

        if (currFullWeight > 0)
        {
            float newWeight1 = currWeight2 / currFullWeight;
            float newWeight2 = currWeight1 / currFullWeight;
            currWeight1 = newWeight1;
            currWeight2 = newWeight2;

            targetHeight1 = minHeight + (currWeight1 * (maxHeight - minHeight));
            targetHeight2 = minHeight + (currWeight2 * (maxHeight - minHeight));
        }
        else
        {
            targetHeight1 = minHeight + (0.5f * (maxHeight - minHeight));
            targetHeight2 = minHeight + (0.5f * (maxHeight - minHeight));
        }
    }
Esempio n. 10
0
    private void CollidePoint(int layerMask, Vector2 offset, Vector2 displacement, Action <Vector2> resolution)
    {
        Vector2 position = new Vector2(transform.position.x, transform.position.y);

        nonAlloc[0] = null;
        Physics2D.OverlapAreaNonAlloc(position + offset, position + offset + displacement, nonAlloc, layerMask);
        if (nonAlloc[0] != null)
        {
            resolution(displacement);
        }
    }
Esempio n. 11
0
 public bool isGrounded()
 {
     // print ("ground");
     if (Physics2D.OverlapAreaNonAlloc(leftmost.position, rightmost.position, platforms, staticCollider) > 0)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 12
0
    public int overlapAreaAll(Collider2D[] hits)
    {
        BoxCollider2D collider = GetComponent <BoxCollider2D>();

        if (collider == null)
        {
            return(0);
        }
        Vector2 topLeft  = (Vector2)transform.position + collider.offset - new Vector2(collider.size.x / 2, collider.size.y / 2);
        Vector2 botRight = (Vector2)transform.position + collider.offset + new Vector2(collider.size.x / 2, collider.size.y / 2);

        return(Physics2D.OverlapAreaNonAlloc(topLeft, botRight, hits));
    }
Esempio n. 13
0
        public int OverlapAreaNonAlloc(Vector2 areaSize, LayerMask thingsToHit, ref Collider2D[] results)
        {
            Vector2 topLeft;

            topLeft.x = transform.position.x - (areaSize.x / 2);
            topLeft.y = transform.position.y + (areaSize.y / 2);

            Vector2 bottomRight;

            bottomRight.x = transform.position.x + (areaSize.x / 2);
            bottomRight.y = transform.position.y - (areaSize.y / 2);
            return(Physics2D.OverlapAreaNonAlloc(topLeft, bottomRight, results, thingsToHit));
        }
Esempio n. 14
0
    public override IList GetCurrentTrigger()
    {
        if (!enabled)
        {
            m_len = 0;
        }
        else
        {
            Bounds bds = rect.bounds;

            m_len = Physics2D.OverlapAreaNonAlloc(bds.min, bds.max, m_results, checkLayer);
        }
        return(m_results);
    }
    private void FixedUpdate()
    {
        thisTransform.localPosition += new Vector3(0f, speed * Time.fixedDeltaTime, 0f);
        int count = Physics2D.OverlapAreaNonAlloc((-1f / 2f) * size + thisTransform.position, (1f / 2f) * size + thisTransform.position, colliderHitBuffer, enemyLayer);

        for (int i = 0; i < count; i++)
        {
            colliderHitBuffer[i].GetComponent <BaseEnemy>().health--;
            //Debug.Log("Hit");
        }
        if (count > 0)
        {
            Destroy(gameObject);
        }
    }
Esempio n. 16
0
    void FixedUpdate()
    {
        Bounds box          = GetFloorTestBox();
        int    numColliders = Physics2D.OverlapAreaNonAlloc(box.min, box.max, overlappingColliders);

        isTouchingGround = false;

        for (int i = 0; i < numColliders; i++)
        {
            if (overlappingColliders[i].gameObject != gameObject)
            {
                isTouchingGround = true;
                break;
            }
        }
    }
Esempio n. 17
0
 void FixedUpdate()
 {
     if (!ManagerPause.Pause && !ManagerStop.Stop)
     {
         if (!useArea)
         {
             isCollide = Physics2D.OverlapCircleNonAlloc(objectCheck.position, objectRadius, result, whatIsCollide) > 0;
         }
         else
         {
             isCollide = Physics2D.OverlapAreaNonAlloc(new Vector2(pointA.x + objectCheck.position.x, pointA.y + objectCheck.position.y),
                                                       new Vector2(pointB.x + objectCheck.position.x, pointB.y + objectCheck.position.y),
                                                       result, whatIsCollide) > 0;
         }
     }
 }
Esempio n. 18
0
    void GroundCheck()
    {
        Bounds box          = groundDetection.bounds;
        int    numColliders = Physics2D.OverlapAreaNonAlloc(box.min, box.max, overlappingColliders);

        isTouchingGround = false;

        for (int i = 0; i < numColliders; i++)
        {
            if (overlappingColliders[i].gameObject != gameObject)
            {
                isTouchingGround = true;

                break;
            }
        }
    }
Esempio n. 19
0
    // Update is called once per frame
    void FixedUpdate()
    {
        m_Grounded = false;
        m_Walled   = false;
        m_Climb    = false;

        // The player is grounded if a circlecast to the groundcheck position hits anything designated as ground
        // This can be done using layers instead but Sample Assets will not overwrite your project settings.
        int max = Physics2D.OverlapCircleNonAlloc(m_GroundCheck.position, k_GroundedRadius, colliders, m_WhatIsGround);

        for (int i = 0; i < max; i++)
        {
            if (colliders[i].gameObject != gameObject)
            {
                m_Grounded = true;
            }
        }
        if (!m_Grounded)
        {
            max = Physics2D.OverlapAreaNonAlloc(m_WallCheck.position + Vector3.left * largeur + Vector3.up * hauteur, m_WallCheck.position + Vector3.right * largeur + Vector3.down * hauteur, colliders, m_WhatIsGround);
            for (int i = 0; i < max; i++)
            {
                if (colliders[i].gameObject != gameObject)
                {
                    m_Walled = true;
                }
            }
            if (m_Walled)
            {
                m_Climb = true;
                max     = Physics2D.OverlapAreaNonAlloc(m_WallCheck.position + Vector3.left * largeur * 4 + Vector3.up * (hauteur + hauteurClimb), m_WallCheck.position + Vector3.right * largeur * 4 + Vector3.up * hauteur, colliders, m_WhatIsGround);
                for (int i = 0; i < max; i++)
                {
                    if (colliders[i].gameObject != gameObject)
                    {
                        m_Climb = false;
                    }
                }
            }
        }

        m_Anim.SetBool("Ground", m_Grounded);

        //Set the vertical animation
        m_Anim.SetFloat("vSpeed", m_Rigidbody2D.velocity.y);
    }
Esempio n. 20
0
    void CollisionCheck()
    {
        // Translate GameObject point markers to Vector2 (probably very slow and inefficient but I couldn't figure it out yet)
        groundPointA = GgroundPointA.transform.position;
        groundPointB = GgroundPointB.transform.position;

        leftWallPointA = GleftWallPointA.transform.position;
        leftWallPointB = GleftWallPointB.transform.position;

        rightWallPointA = GrightWallPointA.transform.position;
        rightWallPointB = GrightWallPointB.transform.position;

        // Check if area created by point A to B (below character cube) overlaps with Layer Mask (level) and throws overlap results into overlaps array
        grounded      = Physics2D.OverlapAreaNonAlloc(groundPointA, groundPointB, overlaps, layer);
        leftWallHang  = Physics2D.OverlapAreaNonAlloc(leftWallPointA, leftWallPointB, overlaps, layer);
        rightWallHang = Physics2D.OverlapAreaNonAlloc(rightWallPointA, rightWallPointB, overlaps, layer);
    }
Esempio n. 21
0
    void UpdateLines()
    {
        if (!isServer)
        {
            return;
        }
        int lineZero = GameManager.singleton.lineZero;
        int colZero  = GameManager.singleton.columnZero;

        Collider2D[] colliders = new Collider2D[20];
        int          walls;
        int          layerID   = LayerMask.NameToLayer("Tetroid"); // 0-31
        int          layerMask = 1 << layerID;
        int          i         = lineZero;

        while (i <= -lineZero)
        {
            walls = 0;
            walls = Physics2D.OverlapAreaNonAlloc(new Vector2(colZero, i - 0.25f), new Vector2(-colZero, i + 0.25f), colliders, layerMask);
            if (walls == (-colZero) * 2 + 1)          // Line completed
            {
                GameManager.singleton.rowsCompleted++;
                GameManager.singleton.arkanoidY -= 1;
                frequency     += 0.01f;
                Time.timeScale = frequency;
                for (int a = 0; a < walls; a++)
                {
                    NetworkServer.Destroy(colliders[a].gameObject);
                }
                for (int j = i + 1; j <= -lineZero; j++)
                {
                    walls = Physics2D.OverlapAreaNonAlloc(new Vector2(colZero, j - 0.25f), new Vector2(-colZero, j + 0.25f), colliders, layerMask);
                    for (int a = 0; a < walls; a++)
                    {
                        colliders[a].transform.Translate(Vector2.down, Space.World);
                    }
                }
            }
            else
            {
                i++;
            }
        }
    }
        bool EnemyDetected(Vector2 originPosition)
        {
            //Check if the area around this (calculate by multiply by safety area pos) this random pos has any enemies
            Vector2 topLeft     = new Vector2(originPosition.x - TileSize.x * safetyRadius, originPosition.y + TileSize.y * safetyRadius);
            Vector2 bottomRight = new Vector2(originPosition.x + TileSize.x * safetyRadius, originPosition.y - TileSize.y * safetyRadius);

            int n = Physics2D.OverlapAreaNonAlloc(topLeft, bottomRight, overlappedColliders, interactionLayer);

            if (n > 0)
            {
                for (int i = 0; i < n; i++)
                {
                    if (overlappedColliders[i].CompareTag("Enemy"))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 23
0
    public bool IsLedgeDetected(out Collider2D ledge)
    {
        if (_detectionBoxP2 == null || _detectionBoxP1 == null)
        {
            ledge = null;
            return(false);
        }
        var ledgeDetectorUpperBound = LedgeDetectorUpperBound;
        var freeSpaceLowerBound     = FreeSpaceLowerBound;

        var count = Physics2D.OverlapAreaNonAlloc(_detectionBoxP1.transform.position, ledgeDetectorUpperBound, _resultBuffer, _whatIsGround);

        ledge = null;
        for (var idx = 0; idx < count; idx++)
        {
            var collider = _resultBuffer[idx];
            if (!collider.isTrigger)
            {
                ledge = collider;
                break;
            }
        }

        if (ledge == null)
        {
            return(false);
        }

        count = Physics2D.OverlapAreaNonAlloc(freeSpaceLowerBound, _detectionBoxP2.transform.position, _resultBuffer, _whatIsGround);
        for (var idx = 0; idx < count; idx++)
        {
            var collider = _resultBuffer[idx];
            if (!collider.isTrigger)
            {
                ledge = null;
                return(false);
            }
        }

        return(true);
    }
Esempio n. 24
0
        public HealthState CheckHit(Vector2 position)
        {
            var hitsCount = Physics2D.OverlapAreaNonAlloc(_lastPosition, position, _hitColliders);

            _lastPosition = position;

            if (hitsCount == 0)
            {
                return(null);
            }

            var enemyView = _hitColliders[0].GetComponent <IBulletTarget>();

            if (enemyView == null)
            {
                return(null);
            }

            HitPosition = _hitColliders[0].transform.position;
            return(enemyView.HealthState);
        }
Esempio n. 25
0
        // -----------------------------------------------------------------------------------
        /// <summary>
        /// Returns true if there is another play area object in the same position (requires collider)
        /// </summary>
        /// <returns></returns>
        public bool IsOverlapping()
        {
            if (collider == null)
            {
                throw new System.Exception("Cannot determine size without a collider");
            }

            Bounds bounds = collider.bounds;
            int    hits   = Physics2D.OverlapAreaNonAlloc(bounds.min, bounds.max, overlaps, PlayArea.EnemiesLayerMask | PlayArea.BonusesLayerMask);

            bool result = false;

            for (int i = 0; i < hits && !result; i++)
            {
                // it only overlaps if it's not the same object AND if that object is not a child
                result = overlaps[i].gameObject != gameObject &&
                         !overlaps[i].transform.IsChildOf(transform);
            }

            return(result);
        }
    private void FixedUpdate()
    {
        int requestsCount = pendingSplashRequests.Count;

        if (requestsCount > 0)
        {
            for (int i = 0; i < requestsCount; i++)
            {
                SplashRequest splashRequest = pendingSplashRequests[i];
                int           captured      = Physics2D.OverlapAreaNonAlloc(splashRequest.center - splashRequest.size, splashRequest.center + splashRequest.size, splashables, enemyLayer);
                for (int j = 0; j < captured; j++)
                {
                    if (splashables[j] != null)
                    {
                        splashables[j].GetComponent <EnemyDummy>().TakeDamage(splashRequest.damage);
                    }
                }
            }
            pendingSplashRequests.Clear();
        }
    }
Esempio n. 27
0
    protected void CheckPlayerHit(AttackState attack)
    {
        if (!_attackCollider || !_attackCollider.enabled)
        {
            return;
        }

        var pointA = _attackCollider.offset;

        pointA.x *= _movable.GetDirection();
        pointA    = (pointA + (Vector2)transform.position) - _attackCollider.size / 2f;
        var pointB = _attackCollider.offset;

        pointB.x *= _movable.GetDirection();
        pointB    = (pointB + (Vector2)transform.position) + _attackCollider.size / 2f;

        Collider2D[] colliders = new Collider2D[8];

        if (Physics2D.OverlapAreaNonAlloc(pointA, pointB, colliders, (1 << _hitboxColliderLayer.value) | (1 << _attackColliderLayer.value)) <= 0)
        {
            return;
        }

        for (int i = 0; i < colliders.Length; i++)
        {
            var otherCollider = colliders[i];
            if (otherCollider &&
                LayerMask.LayerToName(otherCollider.gameObject.layer) == "HitboxCollider" &&
                otherCollider.gameObject != gameObject)
            {
                var player = otherCollider.GetComponentInParent <Player>();
                if (player && !_attackedPlayer)
                {
                    _attackedPlayer = true;
                    player.Damage(attack.damage);
                }
            }
        }
    }
Esempio n. 28
0
        void Update()
        {
            if (OnCharacterFound == null)
            {
                return;
            }
            var count =
                Physics2D
                .OverlapAreaNonAlloc(
                    _finderAreaP1.position,
                    _finderAreaP2.position,
                    _colliderBuffer,
                    _characterLayer);

            for (var idx = 0; idx < count; idx++)
            {
                var controller = _colliderBuffer[idx].GetComponent <BasePlatformerController>();
                if (controller != null)
                {
                    OnCharacterFound(controller);
                }
            }
        }
Esempio n. 29
0
    private void SpawnButton()
    {
        ButtonSpawnPosition.Set(Random.Range(spawnArea.xMin, spawnArea.xMax),
                                Random.Range(spawnArea.yMin, spawnArea.yMax));
        SetMinMaxSize(ButtonSpawnPosition);
        var attemptToFind = 20;

        while (Physics2D.OverlapAreaNonAlloc(min, max, resOfOverlapAreaNonAlloc) > 1 && attemptToFind > 0)
        {
            ButtonSpawnPosition.Set(Random.Range(spawnArea.xMin, spawnArea.xMax),
                                    Random.Range(spawnArea.yMin, spawnArea.yMax));
            SetMinMaxSize(ButtonSpawnPosition);
            attemptToFind--;
        }

        if (Physics2D.OverlapAreaNonAlloc(min, max, resOfOverlapAreaNonAlloc) != 1)
        {
            return;
        }
        var btn = Instantiate(button, ButtonSpawnPosition, Quaternion.identity);

        btn.GameController = this;
    }
Esempio n. 30
0
    public List <Unit> GetAllUnitsOnScreen()
    {
        Camera cam = Camera.main;

        cameraBounds = cam.OrthographicBounds();
        Vector2 pointA = cameraBounds.min;
        Vector2 pointB = cameraBounds.max;

        onScreenUnits.Clear();
        unitsOnScreen = Physics2D.OverlapAreaNonAlloc(pointA, pointB, results);
        for (int i = 0; i < unitsOnScreen; i++)
        {
            Unit u = results[i].GetComponentInParent <Unit>();
            if (u != null)
            {
                if (!onScreenUnits.Contains(u))
                {
                    onScreenUnits.Add(u);
                }
            }
        }
        return(onScreenUnits);
    }