Example #1
0
    IEnumerator FixPath()
    {
        if (fixingPath == false && agent != null && target != null && !agent.CalculatePath(target.position, agent.path))
        {
            fixingPath = true;

            // create temp target
            Destroy(tempObject);
            tempObject      = new GameObject();
            tempObject.tag  = "Temporary";
            tempObject.name = "Temporary AI Waypoint";
            tempObject.transform.position = this.target.position;

            // hold on to original target
            originalObject = target.gameObject;

            AIMovementManager movement = GetComponent <AIMovementManager>();

            Vector3 newPos = gameObject.DirectionToObject(originalObject);
            newPos.Normalize();
            yield return(null);

            tempObject.transform.position = gameObject.transform.position += (new Vector3(newPos.x * 8, newPos.y * 2, newPos.z * 8));

            movement.RemoveTarget(0);
            movement.AddTarget(tempObject);
            yield return(null);
        }
        yield return(null);

        fixingPath = false;
    }
    void AddItemToDesiredList(GameObject item)
    {
        ItemProperties properties = item.GetComponent <ItemProperties>();

        if (properties == null || desiredItems.Contains(item))
        {
            return;
        }

        movement.AddTarget(item);
        desiredItems.Add(item);

        properties.AddListener(ItemWasCollected);
    }