Esempio n. 1
0
        IEnumerator MoveToEnemy(GameObject target)
        {
            var         time            = 0f;
            var         targetComponent = target.GetComponent <Enemy>();
            Coordinates step;

            do
            {
                var start = Spawn.pCache.p;
                var goal  = targetComponent.p;
                var path  = AstarAlgorithm.GetPath(start, goal, empty, seek: false);
                if (Stop(path[0]))
                {
                    var obstacles = ObstacleSetter.GetObstacles(start, target: target);
                    path = AstarAlgorithm.GetPath(start, goal, obstacles, seek: false);
                    if (Stop(path[0]))
                    {
                        break;
                    }
                }
                step = path.Pop();

                StartCoroutine(Steping(Spawn.player, Spawn.pCache.p, step));
                _Synchronize(Spawn.player, Spawn.pCache, Spawn.pCache.p, step);
                Updater.update = true;
                _Wait();
                time = CalculateTime();
                StartCoroutine(ActEnemies());
                yield return(new WaitForSecondsRealtime(time));
            } while (!Reach(step, target));
            playerTurn = true;
        }
Esempio n. 2
0
        IEnumerator Walk(Coordinates start, Coordinates goal)
        {
            var obstacles = ObstacleSetter.GetObstacles(start, target: null);
            var path      = AstarAlgorithm.GetPath(start, goal, obstacles, seek: false);
            var time      = 0f;

            for (int n = 0; n < path.Count; n++)
            {
                //移動中止のチェック
                if (n > 0 && Stop(path[n]))
                {
                    break;
                }

                StartCoroutine(Steping(Spawn.player, Spawn.pCache.p, path[n]));
                _Synchronize(Spawn.player, Spawn.pCache, Spawn.pCache.p, path[n]);
                Updater.update = true;
                _Wait();
                time = CalculateTime();
                StartCoroutine(ActEnemies());
                yield return(new WaitForSecondsRealtime(time));
            }
            playerTurn = true;
        }