コード例 #1
0
    private void CheckGroundByRaycast()
    {
        RaycastHit2D[] rays     = new RaycastHit2D[5];
        var            rayCount = EnemyCollider.Raycast(Vector2.down, rays);

        _onGround = rayCount > 0 && rays.Any(r =>
                                             r.collider != null &&
                                             r.collider.CompareTag(TagNames.GROUND) &&
                                             r.distance < Size.y + 0.1f);
    }
コード例 #2
0
    IEnumerator Blow()
    {
        WSB_Movable _physics;

        canMove = false;

        // Runs until coroutine is canceled
        while (true)
        {
            // Hold if game is in pause
            while (WSB_GameManager.Paused)
            {
                yield return(new WaitForSeconds(.2f));
            }

            // Find all corresponding objects in range
            Collider2D[] _hits = Physics2D.OverlapCircleAll(transform.position, windRange, windLayer);
            Collider2D   _hit;

            // Loops through found objects
            for (int i = 0; i < _hits.Length; i++)
            {
                _hit = _hits[i];

                // Checks if player is standing on it, stop lifting if yes
                RaycastHit2D[] _checkPlayerOn = new RaycastHit2D[10];
                _hit.Cast(Vector2.up, new ContactFilter2D(), _checkPlayerOn);
                if (_checkPlayerOn.Any(_r => _r && _r.transform.GetComponent <WSB_Player>()))
                {
                    continue;
                }

                // Gets physic of hit object
                _physics = _hit.gameObject.GetComponent <WSB_Movable>();

                // if(raycast(pos, dir(pos, _hits.pos)) pas gêné, blow

                if (_physics)
                {
                    // Checks if object is a pot and try to break the seed in it
                    if (_hit.GetComponent <WSB_Pot>() && _physics.CanMove)
                    {
                        _hit.GetComponent <WSB_Pot>().BreakSeed();
                    }

                    // Add vertical force on the physic of the object
                    _physics.AddForce(Vector2.up * (windPower /* - (Vector2.Distance(transform.position, _hit.transform.position) / 2)*/));
                }
            }
            yield return(new WaitForEndOfFrame());
        }
    }