public static bool TryToChangeState(Beans player) { // 到達可能なWaterBallを目指す var waters = GameObject.FindGameObjectsWithTag("Item") .Where(x => x.GetComponent <WaterBall>().Parent == null) .Where(x => player.IsReachable(x.transform.position)) .ToArray(); if (waters.Any()) { var target = waters[UnityEngine.Random.Range(0, waters.Length)]; StateToWaterBall.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(); } }
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; } } } } }