Exemplo n.º 1
0
    /// <summary>
    /// Gets top priority target from list.
    /// </summary>
    /// <returns>The topmost target.</returns>
    private GameObject GetTopmostTarget()
    {
        GameObject res = null;

        if (useTargetPriority == true) // Get target with minimum distance to capture point
        {
            float minPathDistance = float.MaxValue;
            foreach (GameObject ai in targetsList)
            {
                if (ai != null)
                {
                    AiStatePatrol aiStatePatrol = ai.GetComponent <AiStatePatrol>();
                    float         distance      = aiStatePatrol.GetRemainingPath();
                    if (distance < minPathDistance)
                    {
                        minPathDistance = distance;
                        res             = ai;
                    }
                }
            }
        }
        else // Get first target from list
        {
            res = targetsList[0];
        }
        // Clear list of potential targets
        targetsList.Clear();
        return(res);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Start this instance.
    /// </summary>
    void Start()
    {
        float radius = radiusCollider.radius * Mathf.Max(radiusCollider.transform.localScale.x, radiusCollider.transform.localScale.y);
        // Get random enemy
        Collider2D enemy = Physics2D.OverlapCircle(radiusCollider.transform.position, radius, 1 << LayerMask.NameToLayer("Enemy"));

        if (enemy != null)
        {
            if (fxPrefab != null)
            {
                // Visual effect in teleport position
                GameObject fx = Instantiate(fxPrefab);
                fx.transform.position = enemy.gameObject.transform.position;
                Destroy(fx, fxDuration);
            }
            AiStatePatrol aiStatePatrol = enemy.gameObject.GetComponent <AiStatePatrol>();
            // Offset target on pathway
            Vector2 teleportPosition = aiStatePatrol.path.GetOffsetPosition(ref aiStatePatrol.destination, aiStatePatrol.transform.position, teleportOffset);
            aiStatePatrol.transform.position = new Vector3(teleportPosition.x, teleportPosition.y, aiStatePatrol.transform.position.z);
            // Update patrol destination
            aiStatePatrol.UpdateDestination(false);
            if (fxPrefab != null)
            {
                // Visual effect in new position
                GameObject fx = Instantiate(fxPrefab);
                fx.transform.position = enemy.gameObject.transform.position;
                Destroy(fx, fxDuration);
            }
        }
        Destroy(gameObject);
    }