public void Move(Plataforma newDest)
 {
     if (!waiting)
     {
         path.Enqueue(newDest);
         Plataforma destino = path.Dequeue();
         if (startPlatform.isReachable(destino))
         {
             if (destino.entity == null)
             {
                 attackPlatform = path.Peek();
                 mAnimator.SetBool("walk", true);
                 agent.SetDestination(destino.transform.position + offset);
                 startPlatform.entity = null;
                 startPlatform        = destino;
                 startPlatform.entity = this.gameObject;
                 destino.moved();
             }
         }
         else
         {
             Debug.Log("no reachable");
             path    = new Queue <Plataforma>();
             waiting = true;
         }
     }
 }
 public bool MoveToPoint(Plataforma dest)
 {
     if (!walking & alive & !atacking)
     {
         if (currentPlatform.GetComponent <Plataforma>().isReachable(dest))
         {
             currentPlatform.entity = null;
             currentPlatform        = dest;
             if (dest.entity == null)
             {
                 dest.entity = this.gameObject;
             }
             dest.moved();
             Debug.Log("destination setted");
             agent.SetDestination(dest.transform.position + offset);
             return(true);
         }
     }
     Debug.Log("return false");
     return(false);
 }
예제 #3
0
    public void Move()
    {
        Debug.Log("Move spider");
        bool       moved = false;
        Plataforma now   = currentPlat;

        if (horizontal)
        {
            if (dir == 0)
            {
                if (currentPlat.rightPlat != null)
                {
                    moved = true;
                    currentPlat.entity = null;
                    agent.SetDestination(currentPlat.rightPlat.transform.position);
                    currentPlat = currentPlat.rightPlat;
                }
                else if (currentPlat.leftPlat != null)
                {
                    moved = true;
                    dir   = 1;
                    currentPlat.entity = null;
                    agent.SetDestination(currentPlat.leftPlat.transform.position);
                    currentPlat = currentPlat.leftPlat;
                }
            }
            else
            {
                if (currentPlat.leftPlat != null)
                {
                    moved = true;
                    currentPlat.entity = null;
                    agent.SetDestination(currentPlat.leftPlat.transform.position);
                    currentPlat = currentPlat.leftPlat;
                }
                else if (currentPlat.rightPlat != null)
                {
                    moved = true;
                    dir   = 0;
                    currentPlat.entity = null;
                    agent.SetDestination(currentPlat.rightPlat.transform.position);
                    currentPlat = currentPlat.rightPlat;
                }
            }
        }
        else
        {
            if (dir == 0)
            {
                if (currentPlat.topPlat != null)
                {
                    moved = true;
                    currentPlat.entity = null;
                    agent.SetDestination(currentPlat.topPlat.transform.position + offset);
                    currentPlat = currentPlat.topPlat;
                }
                else if (currentPlat.bottomPlat != null)
                {
                    dir = 1;
                    currentPlat.entity = null;
                    moved = true;
                    agent.SetDestination(currentPlat.bottomPlat.transform.position + offset);
                    currentPlat = currentPlat.bottomPlat;
                }
            }
            else
            {
                if (currentPlat.bottomPlat != null)
                {
                    moved = true;
                    currentPlat.entity = null;
                    agent.SetDestination(currentPlat.bottomPlat.transform.position + offset);
                    currentPlat = currentPlat.bottomPlat;
                }
                else if (currentPlat.topPlat != null)
                {
                    moved = true;
                    dir   = 0;
                    currentPlat.entity = null;
                    agent.SetDestination(currentPlat.topPlat.transform.position + offset);
                    currentPlat = currentPlat.topPlat;
                }
            }
        }
        if (moved)
        {
            if (currentPlat.entity != null)
            {
                Debug.Log("Set Destination now");
                //agent.SetDestination(now.transform.position + offset);
                now.entity = this.gameObject;
                if (currentPlat.entity.tag == "Player")
                {
                    Debug.Log("Spider kills Player");
                }
            }
            else
            {
                currentPlat.entity = this.gameObject;
                currentPlat.moved();
            }
        }
        else
        {
            dir = (dir + 1) % 2;
        }
    }