Exemplo n.º 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);
        }
Exemplo n.º 2
0
        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();
            }
        }