Exemplo n.º 1
0
    void Update()
    {
        if (Vector3.Distance(this.transform.position, pointA.transform.position) <= 0.001f)
        {
            State = GoingTo.B;
        }
        else
        {
            if (Vector3.Distance(this.transform.position, pointB.transform.position) <= 0.001f)
            {
                State = GoingTo.A;
            }
        }

        switch (State)
        {
        case (GoingTo.A):
            Debug.Log("A");
            this.transform.position = Vector3.MoveTowards(this.transform.position, pointA.transform.position, speed * Time.deltaTime);
            break;

        case (GoingTo.B):
            Debug.Log("B");
            this.transform.position = Vector3.MoveTowards(this.transform.position, pointB.transform.position, speed * Time.deltaTime);
            break;
        }
    }
Exemplo n.º 2
0
    private void Awake()
    {
        State = GoingTo.B;

        if (speed == 0)
        {
            speed = 5f;
        }
    }
Exemplo n.º 3
0
        private List <Stack <string> > Solve(int r, int c, Stack <string> cellStack, GoingTo goingTo)
        {
            if (r < 0 || c < 0)
            {
                return(null);
            }
            if (r > size - 1 || c > size - 1)
            {
                return(null);
            }
            if (cell[r, c].IsWall)
            {
                return(null);
            }
            if (cell[r, c].VisitCount > MaxVisitCount)
            {
                return(null);
            }

            List <Stack <string> > listStack = new List <Stack <string> >();
            List <Stack <string> > tempStack = new List <Stack <string> >();

            // If the current cell is already in the stack,
            // we may have a longer path. Optimize it by removing extras.
            while (cellStack.Contains(cell[r, c].RowCol))
            {
                cellStack.Pop();
            }

            // Push current cell back.
            cellStack.Push(cell[r, c].RowCol);
            cell[r, c].VisitCount++;

            if ((r <= 0 || r >= size - 1) && (c <= 0 || c >= size - 1))
            {
                listStack.Add(cellStack);
            }
            else
            {
                // If not going to bottom, go to top.
                if (!goingTo.Equals(GoingTo.Bottom))
                {
                    // Get all the elements from other chains.
                    tempStack = Solve(r - 1, c, cellStack.Clone <string>(), GoingTo.Top);
                    if (tempStack != null && tempStack.Any())
                    {
                        listStack.AddRange(tempStack);
                    }
                }

                // If not going to right, go to left.
                if (!goingTo.Equals(GoingTo.Right))
                {
                    tempStack = Solve(r, c - 1, cellStack.Clone <string>(), GoingTo.Left);
                    if (tempStack != null && tempStack.Any())
                    {
                        listStack.AddRange(tempStack);
                    }
                }

                // If not going to left, go to right.
                if (!goingTo.Equals(GoingTo.Left))
                {
                    tempStack = Solve(r, c + 1, cellStack.Clone <string>(), GoingTo.Right);
                    if (tempStack != null && tempStack.Any())
                    {
                        listStack.AddRange(tempStack);
                    }
                }

                // If not going to top, go to bottom.
                if (!goingTo.Equals(GoingTo.Top))
                {
                    tempStack = Solve(r + 1, c, cellStack.Clone <string>(), GoingTo.Bottom);
                    if (tempStack != null && tempStack.Any())
                    {
                        listStack.AddRange(tempStack);
                    }
                }
            }

            return(listStack);
        }