Пример #1
0
    bool CanBeAppliedDistanceCheck(SelectableCharacter myChar, SelectableCharacter targetChar)
    {
        bool result   = false;
        var  distance = (myChar.gameObject.transform.position - targetChar.gameObject.transform.position).magnitude;

        if (distance <= MaxUseDistance)
        {
            switch (distanceType)
            {
            case DISTANCE_TYPE.MELEE:
                result = true;
                var        rayStart = myChar.GetComponent <Collider>().bounds.center;
                var        ray      = new Ray(rayStart, targetChar.GetComponent <Collider>().bounds.center - rayStart);
                RaycastHit hitInfo;
                if (Physics.Raycast(ray, out hitInfo, MaxUseDistance))
                {
                    Debug.DrawLine(ray.origin, hitInfo.point, Color.red, 1.0f);
                    if (hitInfo.collider.gameObject == targetChar.gameObject)
                    {
                        result = true;
                    }
                    else
                    {
                        result = false;
                        Debug.Log(myChar.name + "CAN'T perform MELEE attack to " + targetChar.name + " due to occlusion");
                    }
                }
                else
                {
                    Debug.DrawRay(ray.origin, ray.direction, Color.green, 1.0f);
                }
                break;

            case DISTANCE_TYPE.RANGED:
                result = true;
                break;

            case DISTANCE_TYPE.MAGICAL:
                result = true;
                break;
            }
        }
        else
        {
            Debug.Log(myChar.name + "CAN'T perform attack to " + targetChar.name + " due to DISTANCE: " + distance + ">" + MaxUseDistance);
            result = false;
        }
        return(result);
    }
Пример #2
0
 internal void ChangeToSelectedCharacter(SelectableCharacter character)
 {
     //Debug.Log(this.name + ": Changing to selected character - " + character.name);
     sr.sprite = character.GetComponent <SpriteRenderer>().sprite;
 }