public Player2(PlayerType2 type) : base(CreatureType2.Player) { this.type = type; }
/// <summary> /// 敵の移動処理 /// </summary> /// <param name="fixedUpdate"></param> private void EnemyMove(bool fixedUpdate) { float delta = fixedUpdate ? Time.fixedDeltaTime : Time.deltaTime; if (connectPlayState) { mode = PlayState.playState.gameMode; } inWater = stageWater != null && transform.position.y + enemy.radius < stageWater.max; if (mode == PlayState.GameMode.Play && standby) { int nextLocation; if (finishOneLoop) { nextLocation = location - 1 < 0 ? moveType == EnemyMoveType.Lap ? moveSchedule.Length - 1 : location + 1 : location - 1; } else { nextLocation = location + 1 >= moveSchedule.Length ? moveType == EnemyMoveType.Lap ? 0 : location - 1 : location + 1; } Vector3 nextPos = moveSchedule[nextLocation]; Vector3 forward = (nextPos - transform.position).normalized; // プレイヤーと接触しているかをチェック RaycastHit hit; if (Physics.BoxCast(new Vector3(transform.position.x, transform.position.y - enemy.radius * enemySize, transform.position.z), new Vector3(enemy.radius * enemySize * 1.25f, enemy.radius * enemySize, enemy.radius * enemySize * 1.25f), Vector3.up, out hit, Quaternion.Euler(Vector3.zero), 1.0f, playerLayer)) { // プレイヤーと接触している場合はプレイヤーの方向を向く処理を実行 if (player == null) { player = hit.transform.gameObject.GetComponent <PlayerType2>(); } player.HitEnemy(RotateAnimation(transform.gameObject, (new Vector3(hit.transform.position.x, 0, hit.transform.position.z) - new Vector3(transform.position.x, 0, transform.position.z)).normalized, rotatePower * delta * 2.5f, false)); } else { switch (step) { case 0: transform.position = moveSchedule[location]; if (Vector3.Distance(transform.position, moveSchedule[nextLocation]) < 0.1f) { step = -5; } stepEnd = true; break; case 1: stepEnd = Wait(time, lateTime); time += delta; break; case 2: stepEnd = RotateAnimation(transform.gameObject, forward, rotatePower * delta, false); break; case 3: stepEnd = Wait(time, lateTime); time += delta; break; case 4: if (transform.rotation == Quaternion.LookRotation(forward)) { float vec = Mathf.Abs(forward.x) >= Mathf.Abs(forward.z) ? forward.z / forward.x : forward.x / forward.z; vec = 1.0f / Mathf.Sqrt(1.0f + vec * vec); float speed = inWater ? enemyWaterSpeed : enemySpeed; transform.position += forward * speed * delta * vec; if (Vector3.Distance(transform.position, nextPos) < 0.1f) { stepEnd = true; } } else { step = 2; } break; default: step = 0; if (finishOneLoop) { location--; if (moveType == EnemyMoveType.Lap) { if (location < 0) { location = moveSchedule.Length - 1; } } else { if (location < 1) { finishOneLoop = false; } } } else { location++; if (moveType == EnemyMoveType.Lap) { if (location >= moveSchedule.Length) { location = 0; } } else { if (location >= moveSchedule.Length - 1) { finishOneLoop = true; } } } return; } if (stepEnd) { stepEnd = false; step++; time = 0; } } // 足音の再生 if (enemyAnime != null) { enemyAnime.enabled = true; animationTime += delta; if (animationTime >= animationSpeed) { animationTime = 0; SoundManager.soundManager.PlaySe3D("EnemyMove", transform.position, 0.5f); } } } else { // アニメーションの停止 if (enemyAnime != null) { if (mode == PlayState.GameMode.StartEf || mode == PlayState.GameMode.Stop) { enemyAnime.enabled = true; } else { enemyAnime.enabled = false; } } } }