コード例 #1
0
    void OnTriggerStay2D(Collider2D coll)
    {
        if (target != null && coll.transform == target.transform)
        {
            return;
        }

        if (coll.CompareTag("Player"))
        {
            if (InLineOfSight(coll.transform))
            {
                CombatChar collCombat = coll.GetComponent <CombatChar>();
                if (target == null)
                {
                    target = collCombat;
                }
                if (collCombat.GetAggro() >= target.GetAggro())
                {
                    target = collCombat;
                }
                StartCoroutine(pathfinder.GetWaypoints(transform.position, target.transform.position, this));
                //Debug.DrawLine(transform.position, coll.transform.position);
            }
            else
            {
                //Debug.DrawLine(transform.position, coll.transform.position, Color.red);
            }
        }
    }
コード例 #2
0
    public CombatChar GetAttackTarget(List <CombatChar> targets)
    {
        // Get target from a list of possible targets, ahd pick the one with the highest aggro

        if (targets == null)
        {
            return(null);
        }
        CombatChar target = null;

        foreach (CombatChar tar in targets)
        {
            if (target == null)
            {
                target = tar;
            }
            else
            {
                if (tar.GetAggro() > target.GetAggro())
                {
                    target = tar;
                }
            }
        }
        return(target);
    }