Exemplo n.º 1
0
    protected bool CheckGroundCollision()
    {
        bool ret = false;

        RaycastHit2D[] hits = Physics2D.CircleCastAll(transform.position, 0.3f, transform.up * -1, _rayCastGroundRange, groundMask.value);
        foreach (RaycastHit2D hit in hits)
        {
            if (hit.transform != null)
            {
                if (hit.distance <= 1)
                {
                    Platform p = hit.transform.GetComponent <Platform>();
                    if (p != null)
                    {
                        if (transform.position.y - halfHeight + 0.15f >= p.transform.position.y + p.platformHeight / 2)
                        {
                            if (p.CompareTag(Constants.TAG_SAFETY_NET))
                            {
                                BurstJump(safetyNetJump);
                                p.gameObject.SetActive(false);
                                return(false);
                            }

                            ret = true;
                            DestroyablePlatform dp = hit.transform.gameObject.GetComponent <DestroyablePlatform>();
                            if (dp != null)
                            {
                                dp.StartFalling();
                            }
                        }
                    }
                    else
                    {
                        Enemy e = hit.transform.GetComponent <Enemy>();
                        if (e != null && e._hitsLeft > 0)
                        {
                            if (transform.position.y - halfHeight + 0.5f >= e.transform.position.y + e.spriteHeight / 2)
                            {
                                e.Hit();
                                ret = true;
                            }
                        }
                    }
                }
            }
        }
        return(ret);
    }
Exemplo n.º 2
0
    /*private const float MIN_DELTA = 1.0f;
     * private const float MAX_DELTA = 5.0f;
     * private const float RADIUS = 3.0f;*/

    public override void DealDamage(List <Unit> possibleAims, Unit unit)
    {
        TankParams tankParams = unit.GetParams() as TankParams;

        possibleAims.RemoveAll(target => target == null);

        if (possibleAims.Count == 0)
        {
            return;
        }

        System.Random rand  = new System.Random();
        int           index = rand.Next(possibleAims.Count - 1);

        Unit aim = possibleAims[index];

        Vector2 aimCenter = aim.transform.position;
        float   radius    = unit.GetParams().hitRadius;
        Vector2 point     = Random.insideUnitCircle * radius + aimCenter;

        Vector2 radiusVector   = (point - (Vector2)unit.transform.position).normalized;
        float   delta          = Random.Range(tankParams.minShootError, tankParams.maxShootError);
        Vector2 explosionPoint = point + radiusVector * delta;

        RaycastHit2D[] hits = Physics2D.CircleCastAll(explosionPoint, tankParams.explosionRadius, Vector2.zero);
        foreach (RaycastHit2D hit in hits)
        {
            if (hit.collider == null)
            {
                continue;
            }
            Unit target = hit.collider.GetComponent <Unit>();
            if (target == null ||
                target.unitCollider != hit.collider)
            {
                continue;
            }
            //if (target.GetOwner() == unit.GetOwner())
            //{
            //    continue;
            //}
            target.DealDamage(unit.GetParams().damage);
        }

        GameObject explosionInstance = GameObject.Instantiate(tankParams.explosionPrefab) as GameObject;

        explosionInstance.transform.position = explosionPoint;
    }
Exemplo n.º 3
0
    void explode()
    {
        List <Rigidbody2D> rb2ds = new List <Rigidbody2D>();

        RaycastHit2D[] rch2ds = Physics2D.CircleCastAll(transform.position, explodeRange, Vector2.zero);
        for (int i = 0; i < rch2ds.Length; i++)
        {
            Rigidbody2D rb2d = rch2ds[i].rigidbody;
            if (!rb2d)
            {
                continue;
            }
            if (!rb2ds.Contains(rb2d))
            {
                rb2ds.Add(rb2d);
            }
        }
        foreach (Rigidbody2D rb2d in rb2ds)
        {
            HealthPool hp = rb2d.gameObject.FindComponent <HealthPool>();
            if (hp && entityTypes.Contains(hp.entityType))
            {
                Vector2 explodeDir    = (rb2d.transform.position - transform.position).normalized;
                Vector2 explodeVector = explodeDir * explodePower;
                rb2d.velocity = explodeVector;
                //PlayerMovement
                PlayerMovement playerMovement = rb2d.gameObject.FindComponent <PlayerMovement>();
                if (playerMovement)
                {
                    //TODO: refactor this once MovementLayer has been implemented
                    float speed = explodePower / playerMovement.MovementSpeed;
                    playerMovement.forceMovement(explodeVector, true);
                    int       viewID    = gameObject.FindComponent <PhotonView>().ViewID;
                    StatLayer statLayer = new StatLayer(StatLayer.STAT_IGNORE)
                    {
                        moveSpeed = speed
                    };
                    StatKeeper statKeeper = playerMovement.gameObject.FindComponent <StatKeeper>();
                    statKeeper.selfStats.addLayer(viewID, statLayer);
                    TimerManager.StartTimer(forceMoveDuration, () =>
                    {
                        playerMovement.forceMovement(false);
                        statKeeper.selfStats.removeLayer(viewID);
                    });
                }
            }
        }
    }
    /// <summary>
    /// 충돌 및 데미지 이벤트 전달을 처리합니다.
    /// </summary>
    public void ProcessCollision()
    {
        Vector2 point   = owner.transform.position;
        Vector2 forward = owner.transform.right;

        var   hitInfos  = Physics2D.CircleCastAll(point, data.Radius, forward, data.CircleCastDistance, data.CollideLayerMask.value);
        float halfAngle = data.Angle * 0.5f;

        foreach (var hitInfo in hitInfos)
        {
            //범위(Angle) 내에서 충돌이 발생한 Collider만 충돌로 판정해야 한다.
            Vector2 dir   = ((Vector2)hitInfo.transform.position - point).normalized;
            float   angle = Vector2.Angle(forward, dir);

            bool withinRange = angle < halfAngle;


            if (withinRange)
            {
                //범위 내 Collider인 경우, 충돌 이벤트 처리.
                FieldObject target = hitInfo.collider.GetComponent <FieldObject>();
                if (target == null)
                {
                    target = hitInfo.collider.GetComponentInParent <FieldObject>();
                }

                if (target != null && !attackedEntityList.Contains(target))
                {
                    // 적이면 데미지 가함
                    if (owner.EntityGroup.IsHostileTo(target.EntityGroup))
                    {
                        var info = new DamageInfo
                        {
                            Sender = owner,
                            Target = target,
                            amount = data.Damage
                        };
                        var cmd = DamageCommand.Create(info);
                        cmd.Execute();

                        attackedEntityList.Add(target);
                    }
                }
            }
        }

        //GLDebug.DrawSector(new Circle(point, Radius, forward), Angle, DebugColor, 1f);
    }
Exemplo n.º 5
0
    private void Explode()
    {
        FindObjectOfType <AudioManager>().Play("Explosion");

        RaycastHit2D[] hits = Physics2D.CircleCastAll(transform.position, explosionRadius, Vector2.zero);
        foreach (RaycastHit2D hit in hits)
        {
            if (hit.transform.CompareTag("Player"))
            {
                hit.transform.GetComponent <PlayerController>().TakeDamage(explosionDamage);

                Instantiate(explosionObj, transform.position, transform.rotation);
                Destroy(gameObject);
            }
        }
    }
Exemplo n.º 6
0
    void Water()
    {
        int     layerMask     = 1 << LayerMask.NameToLayer("Interactable");
        Vector2 castDirection = new Vector2(animator.GetFloat("Horizontal"), animator.GetFloat("Vertical"));

        RaycastHit2D[] hits = Physics2D.CircleCastAll((Vector2)transform.position + (castDirection * waterRange), waterAOE, castDirection, 0f, layerMask);
        Instantiate(waterEffect, (Vector2)transform.position + (castDirection * waterRange), Quaternion.identity);
        foreach (RaycastHit2D hit in hits)
        {
            Waterable m = hit.collider.GetComponent <Waterable>();
            if (m)
            {
                m.Watered();
            }
        }
    }
Exemplo n.º 7
0
    private void SleepTargets(Vector3 position)
    {
        RaycastHit2D[] hits = Physics2D.CircleCastAll(position, radius * 2, Vector3.zero);
        foreach (RaycastHit2D hit in hits)
        {
            if (hit.collider.tag == "Plant_Food")
            {
                continue;
            }

            SleepingBehaviour sleep     = hit.collider.gameObject.AddComponent <SleepingBehaviour>();
            GameObject        zzzObject = Instantiate(zzzEffectPrefab, hit.collider.transform.position, transform.rotation, hit.collider.transform);
            sleep.ZzzEffect = zzzObject;
            sleep.SleepFor(duration);
        }
    }
Exemplo n.º 8
0
    Collider2D FindCloseEnemy()
    {
        float dist = 0.5f;

        Debug.DrawLine(transform.position, transform.position + Vector3.right * dist);
        RaycastHit2D[] hits = Physics2D.CircleCastAll(transform.position, dist, Vector2.zero);

        foreach (RaycastHit2D hit in hits)
        {
            if (hit.collider.tag == "Enemy" && hit.collider.transform != transform)
            {
                return(hit.collider);
            }
        }
        return(null);
    }
Exemplo n.º 9
0
 private void Update()
 {
     if (CanEndFire())
     {
         RaycastHit2D[] hits = Physics2D.CircleCastAll(lineRenderer.StartPoint, lineRenderer.EndWidth * 0.5f,
                                                       lineRenderer.EndPoint - lineRenderer.StartPoint, Vector3.Distance(lineRenderer.EndPoint, lineRenderer.StartPoint));
         if (hits != null && hits.Length != 0)
         {
             EndFire(hits[0].point);
             if (HitCallback != null)
             {
                 HitCallback(hits);
             }
         }
     }
 }
Exemplo n.º 10
0
    public bool PerformStrike()
    {
        RaycastHit2D[] hits = Physics2D.CircleCastAll(collider.bounds.center, collider.radius, Vector2.right, 0.0f);
        //print("Striking: " + hits.Length);

        for (int i = 0; i < hits.Length; i++)
        {
            //print("hit: " + hits[i].collider.gameObject.name);
            Strikeable strikeable = hits[i].collider.gameObject.GetComponent <Strikeable>();
            if (strikeable != null)
            {
                strikeable.Strike(parent, damage);
            }
        }
        return(hits.Length > 0);
    }
Exemplo n.º 11
0
        /// Returns the first item hit by the circle cast.
        /// For some items this may return a child GameObject.
        /// The caller is expected to check this.
        GameObject CircleCastForItem()
        {
            var hits = Physics2D.CircleCastAll(
                gameObject.transform.position,
                1f,
                Vector2.zero,
                Mathf.Infinity,
                1 << Layers.items | 1 << Layers.noncollidingItems);

            if (hits.Length == 0)
            {
                return(null);
            }

            return(hits[0].collider.gameObject);
        }
Exemplo n.º 12
0
    private void OnLand()
    {
        RaycastHit2D[] hits = Physics2D.CircleCastAll(transform.position + Vector3.left * (circleCollider.radius * 2f),
                                                      circleCollider.radius,
                                                      Vector3.left,
                                                      Singleton.Instanse.screen.x / 4f);

        for (int i = 0; i < hits.Length; i++)
        {
            if (hits[i].collider.gameObject.GetComponent <Barrier>() != null)
            {
                level.NearBarrierScore(Physics2D.Distance(circleCollider, hits[i].collider).distance, hits[i].collider.transform);
                break;
            }
        }
    }
Exemplo n.º 13
0
    private void ShootZombieDisease(Vector3 position)
    {
        RaycastHit2D[] hits = Physics2D.CircleCastAll(position, radius * 2, Vector3.zero);
        foreach (RaycastHit2D hit in hits)
        {
            HerbivoreBehaviour herbivore = hit.collider.GetComponent <HerbivoreBehaviour>();
            if (herbivore == null || herbivore.GetComponent <ZombieHerbivoreBehaviour>() != null)
            {
                continue;
            }

            ZombieHerbivoreBehaviour zombie = herbivore.gameObject.AddComponent <ZombieHerbivoreBehaviour>();
            GameObject diseaseEffect        = Instantiate(diseaseEffectPrefab, hit.collider.transform.position, transform.rotation, hit.collider.transform);
            zombie.DiseaseEffect = diseaseEffect;
        }
    }
Exemplo n.º 14
0
    void WallOpening()
    {
        //Using prevously stored positions in between each pair of collision points to detect and destroy walls

        for (int i = 0; i < inBetweenPoints.Count; i++)
        {
            RaycastHit2D[] hits = Physics2D.CircleCastAll(inBetweenPoints[i], 0.4f, Vector2.zero);
            foreach (RaycastHit2D hit in hits)
            {
                if (hit.collider.gameObject.CompareTag("Walls"))
                {
                    Destroy(hit.collider.transform.gameObject);
                }
            }
        }
    }
Exemplo n.º 15
0
 // Start is called before the first frame update
 public override void getEffectedList(float abilityRange, LayerMask mask)
 {
     effectedList = new List <GameObject>();
     //base.getEffectedList(abilityRange);
     RaycastHit2D[] tempGO = Physics2D.CircleCastAll(transform.position, abilityRange, new Vector2(), 0, layerMask);
     foreach (RaycastHit2D r in tempGO)
     {
         if (r.collider.TryGetComponent <WeaponScript>(out WeaponScript w))
         {
             if (!Physics2D.Raycast(r.transform.position, transform.position - r.transform.position, (transform.position - r.transform.position).magnitude, mask))
             {
                 effectedList.Add(r.collider.gameObject);
             }
         }
     }
 }
Exemplo n.º 16
0
    public IEnumerator CastCircle(Vector2 startPoint, float width, Vector2 endPoint, float distance)
    {
        yield return(null);

        Vector2 trans = endPoint - startPoint;

        trans.Normalize();
        RaycastHit2D[] ourRayCastHitArray = Physics2D.CircleCastAll(startPoint, width, trans, distance, enemyLayermask);
        foreach (RaycastHit2D hit in ourRayCastHitArray)
        {
            IDamageable damageableObject = hit.collider.GetComponent <IDamageable>();
            if (damageableObject != null)
            {
            }
        }
    }
Exemplo n.º 17
0
    public void Move()
    {
        currentSpeed = Mathf.SmoothDamp(currentSpeed, targetSpeed, ref cv, 0.1f);
        RaycastHit2D[] hits = Physics2D.CircleCastAll(transform.position, collider.radius, moveDirection, currentSpeed, CollisionLayers);

        if (hits.Length > 0)
        {
            // valid collision
            currentSpeed       = targetSpeed = 0;      //((hits[0].point - (Vector2)transform.position)*collider.radius).magnitude;
            transform.position = hits[0].point + hits[0].normal * collider.radius;
        }
        else
        {
            transform.position += moveDirection * currentSpeed;
        }
    }
Exemplo n.º 18
0
    static public List <Angle> Blocked(Vector2 position, float range, List <string> detectionTags)
    {
        List <Angle> blockedDirections = new List <Angle>();

        RaycastHit2D[] hits = Physics2D.CircleCastAll(position, range, Vector2.zero);
        foreach (RaycastHit2D hit in hits)
        {
            if (detectionTags.Contains(hit.collider.tag))
            {
                Vector3 dir          = hit.point - position;
                float   blockedAngle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
                blockedDirections.Add(new Angle(blockedAngle, 40f));
            }
        }
        return(blockedDirections);
    }
Exemplo n.º 19
0
 public void ScanForTrade()
 {
     RaycastHit2D[] hits = Physics2D.CircleCastAll(transform.position, tradeRadius, transform.forward, tradeRadius, LayerMask.GetMask("Vehicle"));
     if (hits.Length > 1)
     {
         List <VehicleClass> nearbyvehicles = new List <VehicleClass>();
         for (int i = 0; i < hits.Length; i++)
         {
             if (hits[i].transform.gameObject.GetComponent <VehicleClass>() != this)
             {
                 nearbyvehicles.Add(hits[i].transform.gameObject.GetComponent <VehicleClass>());
             }
         }
         vehicleGraphics.EnableTrade(nearbyvehicles.ToArray());
     }
 }
Exemplo n.º 20
0
    public static GameObject GetNearbyEnemyWithCircleCollider(Vector3 position, float radius)
    {
        RaycastHit2D[] collision = Physics2D.CircleCastAll(position, radius, Vector2.zero, 0);

        foreach (RaycastHit2D temp in collision)
        {
            if (temp.collider != null)
            {
                if (temp.collider.gameObject.tag == "Monster")
                {
                    return(temp.collider.gameObject);
                }
            }
        }
        return(null);
    }
Exemplo n.º 21
0
 public RaycastHit2D[] Interact()
 {
     RaycastHit2D[] circleCast = Physics2D.CircleCastAll(transform.position,
                                                         GetComponent <CapsuleCollider2D>().size.x,
                                                         inputPlayer.LookDirection.normalized,
                                                         2f,
                                                         layerMaskInteration);
     if (circleCast != null)
     {
         return(circleCast);
     }
     else
     {
         return(null);
     }
 }
        private void CheckHit()
        {
            RaycastHit2D[] hits;
            hits = Physics2D.CircleCastAll(bullet.cachedTransform.position, bullet.data.size, Vector2.zero, 0, layerMask);
            for (int i = 0; i < hits.Length; i++)
            {
                //Debug.Log("!!!!!!!!!!hit " + hits[i].collider.name);
                HIT result = Hit(hits[i].collider);
                switch (result)
                {
                case HIT.ENEMY:
                    //Debug.Log("Hit Enemy:" + name);
                    if (pierce < 99999)
                    {
                        pierce--;
                    }
                    if (!isSplash)
                    {
                        CheckPierce();
                    }
                    break;

                case HIT.WALL:
                    //Debug.Log("Hit Wall:" + name + ", " + hits[i].collider.name + " " + hits[i].point);

                    if (!isHitableWall)
                    {
                        pierce = 0;
                        if (!isSplash)
                        {
                            CheckPierce();
                        }
                    }
                    break;
                    //case HIT.FRIENDLY:
                    //    Debug.Log("Hit Friendly:"+name);
                    //    break;
                    //case HIT.ETC:
                    //    Debug.Log("Hit ETC:" + name);
                    //    break;
                }
            }
            if (isSplash)
            {
                CheckPierce();
            }
        }
Exemplo n.º 23
0
    void escape()
    {
        leftCircleHit  = Physics2D.CircleCastAll(this.transform.position, 1.0f, Vector2.left, escapeDistance * 2);
        rightCircleHit = Physics2D.CircleCastAll(this.transform.position, 1.0f, Vector2.right, escapeDistance * 2);

        for (int i = 0; i < leftCircleHit.Length; i++)
        {
            if (leftCircleHit [i].collider.tag == "wall")
            {
                if (!facingRight)
                {
                    facingRight = true;
                    charMove.flipChar(this.gameObject);
                }

                charMove.hMove(rb, moveSpeed, maxSpeed, "right");
            }
            else if (leftCircleHit [i].collider.tag == "Player")
            {
                for (int y = 0; y < rightCircleHit.Length; y++)
                {
                    if (rightCircleHit [y].collider.tag == "wall")
                    {
                        wallHit = true;

                        if (facingRight)
                        {
                            facingRight = false;
                            charMove.flipChar(this.gameObject);
                        }

                        charMove.hMove(rb, moveSpeed, maxSpeed, "left");
                    }
                    else
                    {
                        if (!facingRight)
                        {
                            facingRight = true;
                            charMove.flipChar(this.gameObject);
                        }

                        charMove.hMove(rb, moveSpeed, maxSpeed, "right");
                    }
                }
            }
        }
    }
Exemplo n.º 24
0
    void Update()
    {
        if (true)        // !ImmortalMode
        {
            if (Application.platform == RuntimePlatform.WindowsEditor & !IsPaused)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    hits = Physics2D.CircleCastAll(Camera.main.ScreenToWorldPoint(Input.mousePosition), 0.30F, Vector2.zero);
                    foreach (RaycastHit2D hit in hits)
                    {
                        if (hit.transform.tag == "Trump")
                        {
                            hit.transform.GetComponent <CandidateScript>().PrepareToDie();
                        }
                    }
                }
            }
            if (Input.touchCount > 0 & !IsPaused)
            {
                if (Input.touchCount >= 2)
                {
                    localTouchBlock = 2;
                }
                else
                {
                    localTouchBlock = 1;
                }

                for (int i = 0; i < localTouchBlock; i++)
                {
                    if (Input.GetTouch(i).phase == TouchPhase.Began)
                    {
                        TapsTotal += 1;
                        hits       = Physics2D.CircleCastAll(Camera.main.ScreenToWorldPoint(Input.GetTouch(i).position), 0.35f, Vector2.zero);   // было ровно 0.3f
                        foreach (RaycastHit2D hit in hits)
                        {
                            if (hit.transform.tag == "Trump")
                            {
                                hit.transform.GetComponent <CandidateScript>().PrepareToDie();
                            }
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 25
0
    // Update is called once per frame
    void Update()
    {
        bool drawBallAtCollision = false;

        Vector2 offsetHitPoint = new Vector2();

        RaycastHit2D[] circleCastHit2DArray = Physics2D.CircleCastAll(rigid.position, ballCollider.radius, rigid.velocity.normalized);

        foreach (RaycastHit2D circleCastHit2D in circleCastHit2DArray)
        {
            if (circleCastHit2D.collider != null && circleCastHit2D.collider.GetComponent <BallControl>() == null)
            {
                Vector2 hitPoint  = circleCastHit2D.point;
                Vector2 hitNormal = circleCastHit2D.normal;

                offsetHitPoint = hitPoint + hitNormal * ballCollider.radius;

                DottedLine.DottedLine.Instance.DrawDottedLine(ball.transform.position, offsetHitPoint);


                if (circleCastHit2D.collider.GetComponent <SideWall>() == null)
                {
                    Vector2 invector = (offsetHitPoint - ball.TrajectoryOrigin).normalized;

                    Vector2 outVector = Vector2.Reflect(invector, hitNormal);

                    float outdot = Vector2.Dot(outVector, hitNormal);

                    if (outdot > -1.0f && outdot < 1.0)
                    {
                        DottedLine.DottedLine.Instance.DrawDottedLine(offsetHitPoint, offsetHitPoint + outVector * 10f);

                        drawBallAtCollision = true;
                    }
                }
            }
        }
        if (drawBallAtCollision)
        {
            ballAtCollision.transform.position = offsetHitPoint;
            ballAtCollision.SetActive(true);
        }
        else
        {
            ballAtCollision.SetActive(false);
        }
    }
Exemplo n.º 26
0
 public void DetectEnemies()
 {
     RaycastHit2D[] Enemies = Physics2D.CircleCastAll(transform.position, 6, Vector2.zero);
     if (Enemies != null)
     {
         foreach (var Enemy in Enemies)
         {
             Vector3 e = Enemy.collider.gameObject.transform.position;
             EnemyList.Add(e);
         }
     }
     else
     {
         DetectEnemies();//ad delay
     }
     SpawnFeathers(EnemyList.Count);
 }
Exemplo n.º 27
0
    private void FixedUpdate()
    {
        transform.position = followObj.position;
        var hit = Physics2D.CircleCastAll(transform.position, circleCollider2D.radius, transform.forward);

        if (hit.Length > 0)
        {
            foreach (var obj in hit)
            {
                if (obj.collider.gameObject.CompareTag("Destroyable"))
                {
                    Debug.Log("hit");
                    NewDestroyTiles(obj);
                }
            }
        }
    }
Exemplo n.º 28
0
    public static GameObject[] GetNearbyEnemyWithCircleColliderArray(Vector3 position, float radius)
    {
        RaycastHit2D[]    collision = Physics2D.CircleCastAll(position, radius, Vector2.zero, 0);
        List <GameObject> temp_list = new List <GameObject>();

        foreach (RaycastHit2D temp in collision)
        {
            if (temp.collider != null)
            {
                if (temp.collider.gameObject.tag == "Monster")
                {
                    temp_list.Add(temp.collider.gameObject);
                }
            }
        }
        return(temp_list.ToArray());
    }
Exemplo n.º 29
0
    public static bool CheckForNearbyitemWithCircleCollider(Vector3 position, float radius)
    {
        //RaycastHit2D[] collision = Physics2D.CircleCastAll(transform.position, local_sprite_size.x / 2, Vector2.zero, 0);
        RaycastHit2D[] collision = Physics2D.CircleCastAll(position, radius, Vector2.zero, 0);

        foreach (RaycastHit2D temp in collision)
        {
            if (temp.collider != null)
            {
                if (temp.collider.gameObject.tag == "Item")
                {
                    return(true);
                }
            }
        }
        return(false);
    }
Exemplo n.º 30
0
    private Transform isEnemySubInView()
    {
        RaycastHit2D[] hits = Physics2D.CircleCastAll(transform.position, subFinderRadius, transform.up, subFinderRange, whatIsTarget);

        foreach (RaycastHit2D hit in hits)
        {
            if (hit.collider != null)
            {
                if (hit.collider.GetComponent <Submarine>())
                {
                    return(hit.transform);
                }
            }
        }

        return(null);
    }