Beispiel #1
0
        public static bool TryToChangeState(Beans player)
        {
            // 到達可能な Obstacle を目指す
            var obstacles = GameObject.FindGameObjectsWithTag("Obstacle")
                            .ToList();
            var reachables = new List <GameObject>();

            foreach (var obstacle in obstacles)
            {
                var  hit  = new UnityEngine.AI.NavMeshHit();
                bool ret  = player.Agent.Raycast(obstacle.transform.position, out hit);
                var  diff = (hit.position - obstacle.transform.position);
                diff.y = 0.0f;
                if (diff.magnitude <= 1.0f)
                {
                    reachables.Add(obstacle);
                }
            }

            if (reachables.Any())
            {
                var target = obstacles[UnityEngine.Random.Range(0, reachables.Count)];
                StateToObstacle.ChangeState(player, target);
                return(true);
            }

            return(false);
        }
        public void OnReceiveSignal(Signal signal, GameObject gameObject)
        {
            switch (signal)
            {
            case Signal.ToFarm:
                break;

            case Signal.ToObstacle:
                StateToObstacle.ChangeState(player, gameObject);
                return;

            case Signal.ToWaterBall:
                StateToWaterBall.ChangeState(player, gameObject);
                return;

            default:
                throw new NotImplementedException();
            }
        }
Beispiel #3
0
        private IEnumerator wait()
        {
            while (true)
            {
                yield return(new WaitForSeconds(1));

                if (player.hasWaterBall())
                {
                    if (StateToCell.TryToChangeState(player))
                    {
                        yield break;
                    }
                }
                else
                {
                    bool toObstacle = (0.8f <= UnityEngine.Random.Range(0.0f, 1.0f));
                    if (toObstacle)
                    {
                        // 障害物の破壊へ
                        if (StateToObstacle.TryToChangeState(player))
                        {
                            yield break;
                        }
                        if (StateToWaterBall.TryToChangeState(player))
                        {
                            yield break;
                        }
                    }
                    else
                    {
                        // 水分取得へ
                        if (StateToWaterBall.TryToChangeState(player))
                        {
                            yield break;
                        }
                    }
                }
            }
        }