Esempio n. 1
0
    /**
     * Get the target agent closes to the aimed postion. ( interms of the angle)
     */
    private ICyberAgent getNearestTargetAgent(Vector3 aimedPosition)
    {
        ICyberAgent tempAgent = null;
        float       minAngle  = 999;

        foreach (ICyberAgent target in m_targets)
        {
            if (target != null)
            {
                float angle    = Vector3.Angle(target.getCurrentPosition() - m_selfPosition, aimedPosition - m_selfPosition);
                float distance = Vector3.Distance(target.getCurrentPosition(), m_selfPosition);
                if (angle < minAngle && angle < AUTO_FIRE_ANGLE && target.IsFunctional() && target.getName() != m_selfName && distance < FIRE_DISTANCE)
                {
                    minAngle  = angle;
                    tempAgent = target;
                }
            }
            else
            {
                m_targets.Remove(target);
            }
        }

        if (tempAgent == null)
        {
            m_targetIndicator.transform.position = new Vector3(0, -10, 0);
        }
        else
        {
            m_targetIndicator.transform.localPosition = tempAgent.getCurrentPosition();
            m_targetIndicatorColor.color = tempAgent.getHealthColor();
            m_healthBar.setHealthPercentage(tempAgent.getHealthPercentage());

            if (tempAgent.GetType() == typeof(FlyingAgent))
            {
                m_targetIndicatorColor.enabled = false;
            }
            else
            {
                m_targetIndicatorColor.enabled = true;
            }
        }

        return(tempAgent);
    }