Esempio n. 1
0
    Planetoid AutoAim(Vector2 touchScreenPos)
    {
        // auto aim
        Vector2 worldTouchPos = Camera.main.ScreenToWorldPoint(touchScreenPos);

                #if UNITY_EDITOR
        Debug.DrawLine(worldTouchPos - Vector2.up * _autoAimRadius, worldTouchPos + Vector2.up * _autoAimRadius, Color.green, 2);
        Debug.DrawLine(worldTouchPos - Vector2.right * _autoAimRadius, worldTouchPos + Vector2.right * _autoAimRadius, Color.green, 2);
                #endif

        Collider2D tappedPlanetoidCollider = Physics2D.OverlapCircle(worldTouchPos, _autoAimRadius, _planetoidsManager.PlanetoidsLayer);
        if (tappedPlanetoidCollider != null)
        {
            Planetoid tappedPlanetoid = tappedPlanetoidCollider.GetComponent <Planetoid>();
            if (!tappedPlanetoid.Fading && tappedPlanetoid.GetArea() <= _autoAimAreaThreshold)
            {
                //touchScreenPos = (Vector2)Camera.main.WorldToScreenPoint(tappedPlanetoid.WorldCenterOfMass);
                                #if UNITY_EDITOR
                Debug.DrawLine(tappedPlanetoid.WorldCenterOfMass - Vector2.up, tappedPlanetoid.WorldCenterOfMass + Vector2.up, Color.red, 2);
                Debug.DrawLine(tappedPlanetoid.WorldCenterOfMass - Vector2.right, tappedPlanetoid.WorldCenterOfMass + Vector2.right, Color.red, 2);
                                #endif
                return(tappedPlanetoid);
            }
        }

        return(null);
    }