private void Update() { if (IsSearching) { player_pos = new Vector3( _player.transform.position.x, _player.transform.position.y + 1, _player.transform.position.z ); if (SearchRay()) { //プレイヤーが見えているなら GessHuntTrigger = 1; LookToPlayer(); manager.NowStatus = EnemyStatus.Hunt; } else { if (GessHuntTrigger == 1) { //もし直前まで追いかけていたなら最後に見失った場所まで走る manager.NowStatus = EnemyStatus.GessHunt; Vector2Int PlayerPos = gamemanager.GetPosData(_player); gessRout = gamemanager.ASter(this.gameObject, PlayerPos); if (gessRout.Count != 0) { TargetPos = FindNextTarget(gessRout[gessRout.Count - 1].x, gessRout[gessRout.Count - 1].y); } transform.LookAt(TargetPos); GessHuntTrigger = 0;//トリガーを元に戻す } } } if (manager.NowStatus == EnemyStatus.GessHunt) { //マスに付いたら次のマスへ進む if (TargetPos.x - 0.2f < transform.position.x && transform.position.x < TargetPos.x + 0.2f) { if (TargetPos.z - 0.2f < transform.position.z && transform.position.z < TargetPos.z + 0.2f) { if (gessRout.Count != 0) { gessRout.RemoveAt(gessRout.Count - 1); if (gessRout.Count != 0) { TargetPos = manager.FindNextTarget(gessRout[gessRout.Count - 1].x, gessRout[gessRout.Count - 1].y); transform.LookAt(TargetPos); } else { manager.NowStatus = EnemyStatus.Idling; } } } } } }
void Update() { body = GetComponent <Rigidbody>(); //移動について if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) { Moov("forward"); } if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) { Moov("back"); } if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) { Moov("right"); } if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) { Moov("left"); } //回転 if (Input.GetKey(KeyCode.E)) { transform.Rotate(new Vector3(0, 5, 0)); } if (Input.GetKey(KeyCode.Q)) { transform.Rotate(new Vector3(0, -5, 0)); } if (Input.GetKey(KeyCode.LeftShift)) { //しゃがみ処理 } //デバッグ用リスポーンキー if (Input.GetKey(KeyCode.Alpha1)) { transform.position = new Vector3(0, 5, 10); } if (Input.GetKeyDown(KeyCode.Space)) { Vector2Int aaa = _gameManager.GetPosData(this.gameObject); Debug.Log(" PosX : " + aaa.x + " PosY: " + aaa.y); } if (Input.GetKeyDown(KeyCode.Alpha2)) { List <Vector2Int> ToGorl = new List <Vector2Int>(); ToGorl = _gameManager.ASter(this.gameObject, _gameManager.GorlPos); for (int i = 0; i < ToGorl.Count; i++) { Debug.Log(i + "歩目" + ToGorl[ToGorl.Count - 1 - i]); } } }
//ランダムな場所を取得してそこまでのルートを記録する。 public void RoutReset() { Rout = new List <Vector2Int>(); int TargetRoom = Random.Range(0, _mapcreat.roomCount); int TargetX = Random.Range(_GameManager.Room[TargetRoom].Pos.x, _GameManager.Room[TargetRoom].Pos.x + _GameManager.Room[TargetRoom].Size.x); int TargetY = Random.Range(_GameManager.Room[TargetRoom].Pos.y, _GameManager.Room[TargetRoom].Pos.y + _GameManager.Room[TargetRoom].Size.y); //int TargetRoom = Random.Range(0, _mapcreat.roomCount); //int TargetX = Random.Range(_mapcreat.room[TargetRoom].Pos.x, _mapcreat.room[TargetRoom].Pos.x + _mapcreat.room[TargetRoom].Size.x); //int TargetY = Random.Range(_mapcreat.room[TargetRoom].Pos.y, _mapcreat.room[TargetRoom].Pos.y + _mapcreat.room[TargetRoom].Size.y); Vector2Int End = new Vector2Int(TargetX, TargetY);//目的地の座標 Rout = _GameManager.ASter(this.gameObject, End); }