敵AI Ver.1
This commit is contained in:
8
Assets/Animation.meta
Normal file
8
Assets/Animation.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8ce034fd6ac124826b7c127dcde4673f
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
116
Assets/Animation/New Animator Controller.controller
Normal file
116
Assets/Animation/New Animator Controller.controller
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!1102 &-8424387506954660572
|
||||||
|
AnimatorState:
|
||||||
|
serializedVersion: 6
|
||||||
|
m_ObjectHideFlags: 1
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_Name: New State 0
|
||||||
|
m_Speed: 1
|
||||||
|
m_CycleOffset: 0
|
||||||
|
m_Transitions: []
|
||||||
|
m_StateMachineBehaviours: []
|
||||||
|
m_Position: {x: 50, y: 50, z: 0}
|
||||||
|
m_IKOnFeet: 0
|
||||||
|
m_WriteDefaultValues: 1
|
||||||
|
m_Mirror: 0
|
||||||
|
m_SpeedParameterActive: 0
|
||||||
|
m_MirrorParameterActive: 0
|
||||||
|
m_CycleOffsetParameterActive: 0
|
||||||
|
m_TimeParameterActive: 0
|
||||||
|
m_Motion: {fileID: -203655887218126122, guid: 88a36a1f7977949579ed5a867e5101c7, type: 3}
|
||||||
|
m_Tag:
|
||||||
|
m_SpeedParameter:
|
||||||
|
m_MirrorParameter:
|
||||||
|
m_CycleOffsetParameter:
|
||||||
|
m_TimeParameter:
|
||||||
|
--- !u!1109 &-7115450000239873375
|
||||||
|
AnimatorTransition:
|
||||||
|
m_ObjectHideFlags: 1
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_Name:
|
||||||
|
m_Conditions: []
|
||||||
|
m_DstStateMachine: {fileID: 0}
|
||||||
|
m_DstState: {fileID: -8424387506954660572}
|
||||||
|
m_Solo: 0
|
||||||
|
m_Mute: 0
|
||||||
|
m_IsExit: 0
|
||||||
|
serializedVersion: 1
|
||||||
|
--- !u!1102 &-1659871487230697381
|
||||||
|
AnimatorState:
|
||||||
|
serializedVersion: 6
|
||||||
|
m_ObjectHideFlags: 1
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_Name: New State
|
||||||
|
m_Speed: 1
|
||||||
|
m_CycleOffset: 0
|
||||||
|
m_Transitions: []
|
||||||
|
m_StateMachineBehaviours: []
|
||||||
|
m_Position: {x: 50, y: 50, z: 0}
|
||||||
|
m_IKOnFeet: 0
|
||||||
|
m_WriteDefaultValues: 1
|
||||||
|
m_Mirror: 0
|
||||||
|
m_SpeedParameterActive: 0
|
||||||
|
m_MirrorParameterActive: 0
|
||||||
|
m_CycleOffsetParameterActive: 0
|
||||||
|
m_TimeParameterActive: 0
|
||||||
|
m_Motion: {fileID: -203655887218126122, guid: 377383bfc75b448cc83232a423c4d77b, type: 3}
|
||||||
|
m_Tag:
|
||||||
|
m_SpeedParameter:
|
||||||
|
m_MirrorParameter:
|
||||||
|
m_CycleOffsetParameter:
|
||||||
|
m_TimeParameter:
|
||||||
|
--- !u!91 &9100000
|
||||||
|
AnimatorController:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_Name: New Animator Controller
|
||||||
|
serializedVersion: 5
|
||||||
|
m_AnimatorParameters: []
|
||||||
|
m_AnimatorLayers:
|
||||||
|
- serializedVersion: 5
|
||||||
|
m_Name: Base Layer
|
||||||
|
m_StateMachine: {fileID: 6365640674471234328}
|
||||||
|
m_Mask: {fileID: 0}
|
||||||
|
m_Motions: []
|
||||||
|
m_Behaviours: []
|
||||||
|
m_BlendingMode: 0
|
||||||
|
m_SyncedLayerIndex: -1
|
||||||
|
m_DefaultWeight: 0
|
||||||
|
m_IKPass: 0
|
||||||
|
m_SyncedLayerAffectsTiming: 0
|
||||||
|
m_Controller: {fileID: 9100000}
|
||||||
|
--- !u!1107 &6365640674471234328
|
||||||
|
AnimatorStateMachine:
|
||||||
|
serializedVersion: 6
|
||||||
|
m_ObjectHideFlags: 1
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_Name: Base Layer
|
||||||
|
m_ChildStates:
|
||||||
|
- serializedVersion: 1
|
||||||
|
m_State: {fileID: -1659871487230697381}
|
||||||
|
m_Position: {x: 360, y: 60, z: 0}
|
||||||
|
- serializedVersion: 1
|
||||||
|
m_State: {fileID: -8424387506954660572}
|
||||||
|
m_Position: {x: 360, y: 160, z: 0}
|
||||||
|
m_ChildStateMachines: []
|
||||||
|
m_AnyStateTransitions: []
|
||||||
|
m_EntryTransitions:
|
||||||
|
- {fileID: -7115450000239873375}
|
||||||
|
m_StateMachineTransitions: {}
|
||||||
|
m_StateMachineBehaviours: []
|
||||||
|
m_AnyStatePosition: {x: 50, y: 20, z: 0}
|
||||||
|
m_EntryPosition: {x: 50, y: 120, z: 0}
|
||||||
|
m_ExitPosition: {x: 800, y: 120, z: 0}
|
||||||
|
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
|
||||||
|
m_DefaultState: {fileID: -1659871487230697381}
|
||||||
8
Assets/Animation/New Animator Controller.controller.meta
Normal file
8
Assets/Animation/New Animator Controller.controller.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 00743b1e9c8fd4b80b6bd2205c49690a
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 9100000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
BIN
Assets/Animation/Skin_1@Sword And Shield Impact.fbx
Normal file
BIN
Assets/Animation/Skin_1@Sword And Shield Impact.fbx
Normal file
Binary file not shown.
1490
Assets/Animation/Skin_1@Sword And Shield Impact.fbx.meta
Normal file
1490
Assets/Animation/Skin_1@Sword And Shield Impact.fbx.meta
Normal file
File diff suppressed because it is too large
Load Diff
BIN
Assets/Animation/Skin_1@Sword And Shield Slash.fbx
Normal file
BIN
Assets/Animation/Skin_1@Sword And Shield Slash.fbx
Normal file
Binary file not shown.
110
Assets/Animation/Skin_1@Sword And Shield Slash.fbx.meta
Normal file
110
Assets/Animation/Skin_1@Sword And Shield Slash.fbx.meta
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 88a36a1f7977949579ed5a867e5101c7
|
||||||
|
ModelImporter:
|
||||||
|
serializedVersion: 24200
|
||||||
|
internalIDToNameTable: []
|
||||||
|
externalObjects: {}
|
||||||
|
materials:
|
||||||
|
materialImportMode: 2
|
||||||
|
materialName: 0
|
||||||
|
materialSearch: 1
|
||||||
|
materialLocation: 1
|
||||||
|
animations:
|
||||||
|
legacyGenerateAnimations: 4
|
||||||
|
bakeSimulation: 0
|
||||||
|
resampleCurves: 1
|
||||||
|
optimizeGameObjects: 0
|
||||||
|
removeConstantScaleCurves: 0
|
||||||
|
motionNodeName:
|
||||||
|
animationImportErrors:
|
||||||
|
animationImportWarnings:
|
||||||
|
animationRetargetingWarnings:
|
||||||
|
animationDoRetargetingWarnings: 0
|
||||||
|
importAnimatedCustomProperties: 0
|
||||||
|
importConstraints: 0
|
||||||
|
animationCompression: 3
|
||||||
|
animationRotationError: 0.5
|
||||||
|
animationPositionError: 0.5
|
||||||
|
animationScaleError: 0.5
|
||||||
|
animationWrapMode: 0
|
||||||
|
extraExposedTransformPaths: []
|
||||||
|
extraUserProperties: []
|
||||||
|
clipAnimations: []
|
||||||
|
isReadable: 0
|
||||||
|
meshes:
|
||||||
|
lODScreenPercentages: []
|
||||||
|
globalScale: 1
|
||||||
|
meshCompression: 0
|
||||||
|
addColliders: 0
|
||||||
|
useSRGBMaterialColor: 1
|
||||||
|
sortHierarchyByName: 1
|
||||||
|
importPhysicalCameras: 1
|
||||||
|
importVisibility: 1
|
||||||
|
importBlendShapes: 1
|
||||||
|
importCameras: 1
|
||||||
|
importLights: 1
|
||||||
|
nodeNameCollisionStrategy: 1
|
||||||
|
fileIdsGeneration: 2
|
||||||
|
swapUVChannels: 0
|
||||||
|
generateSecondaryUV: 0
|
||||||
|
useFileUnits: 1
|
||||||
|
keepQuads: 0
|
||||||
|
weldVertices: 1
|
||||||
|
bakeAxisConversion: 0
|
||||||
|
preserveHierarchy: 0
|
||||||
|
skinWeightsMode: 0
|
||||||
|
maxBonesPerVertex: 4
|
||||||
|
minBoneWeight: 0.001
|
||||||
|
optimizeBones: 1
|
||||||
|
generateMeshLods: 0
|
||||||
|
meshLodGenerationFlags: 0
|
||||||
|
maximumMeshLod: -1
|
||||||
|
meshOptimizationFlags: -1
|
||||||
|
indexFormat: 0
|
||||||
|
secondaryUVAngleDistortion: 8
|
||||||
|
secondaryUVAreaDistortion: 15.000001
|
||||||
|
secondaryUVHardAngle: 88
|
||||||
|
secondaryUVMarginMethod: 1
|
||||||
|
secondaryUVMinLightmapResolution: 40
|
||||||
|
secondaryUVMinObjectScale: 1
|
||||||
|
secondaryUVPackMargin: 4
|
||||||
|
useFileScale: 1
|
||||||
|
strictVertexDataChecks: 0
|
||||||
|
tangentSpace:
|
||||||
|
normalSmoothAngle: 60
|
||||||
|
normalImportMode: 0
|
||||||
|
tangentImportMode: 3
|
||||||
|
normalCalculationMode: 4
|
||||||
|
legacyComputeAllNormalsFromSmoothingGroupsWhenMeshHasBlendShapes: 0
|
||||||
|
blendShapeNormalImportMode: 1
|
||||||
|
normalSmoothingSource: 0
|
||||||
|
referencedClips: []
|
||||||
|
importAnimation: 1
|
||||||
|
humanDescription:
|
||||||
|
serializedVersion: 3
|
||||||
|
human: []
|
||||||
|
skeleton: []
|
||||||
|
armTwist: 0.5
|
||||||
|
foreArmTwist: 0.5
|
||||||
|
upperLegTwist: 0.5
|
||||||
|
legTwist: 0.5
|
||||||
|
armStretch: 0.05
|
||||||
|
legStretch: 0.05
|
||||||
|
feetSpacing: 0
|
||||||
|
globalScale: 1
|
||||||
|
rootMotionBoneName:
|
||||||
|
hasTranslationDoF: 0
|
||||||
|
hasExtraRoot: 1
|
||||||
|
skeletonHasParents: 1
|
||||||
|
lastHumanDescriptionAvatarSource: {instanceID: 0}
|
||||||
|
autoGenerateAvatarMappingIfUnspecified: 1
|
||||||
|
animationType: 3
|
||||||
|
humanoidOversampling: 1
|
||||||
|
avatarSetup: 1
|
||||||
|
addHumanoidExtraRootOnlyWhenUsingAvatar: 1
|
||||||
|
importBlendShapeDeformPercent: 1
|
||||||
|
remapMaterialsIfMaterialImportModeIsNone: 0
|
||||||
|
additionalBone: 0
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
8
Assets/Scenes/GameScene.meta
Normal file
8
Assets/Scenes/GameScene.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: eec9d4587636a4aa484f57fbb49fa392
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
File diff suppressed because it is too large
Load Diff
BIN
Assets/Scenes/GameScene/NavMesh-NavMesh.asset
Normal file
BIN
Assets/Scenes/GameScene/NavMesh-NavMesh.asset
Normal file
Binary file not shown.
8
Assets/Scenes/GameScene/NavMesh-NavMesh.asset.meta
Normal file
8
Assets/Scenes/GameScene/NavMesh-NavMesh.asset.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: eb6ec57545ebd42ebad3d47e3990a796
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 23800000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -529,6 +529,67 @@ Transform:
|
|||||||
- {fileID: 319458692}
|
- {fileID: 319458692}
|
||||||
m_Father: {fileID: 1038169031}
|
m_Father: {fileID: 1038169031}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!1001 &923562640
|
||||||
|
PrefabInstance:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Modification:
|
||||||
|
serializedVersion: 3
|
||||||
|
m_TransformParent: {fileID: 0}
|
||||||
|
m_Modifications:
|
||||||
|
- target: {fileID: 7357282918100144838, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
|
||||||
|
propertyPath: m_LocalPosition.x
|
||||||
|
value: -2.0716844
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7357282918100144838, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
|
||||||
|
propertyPath: m_LocalPosition.y
|
||||||
|
value: 0.000000046386532
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7357282918100144838, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
|
||||||
|
propertyPath: m_LocalPosition.z
|
||||||
|
value: -2.3532963
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7357282918100144838, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.w
|
||||||
|
value: 1
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7357282918100144838, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.x
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7357282918100144838, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.y
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7357282918100144838, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.z
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7357282918100144838, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
|
||||||
|
propertyPath: m_LocalEulerAnglesHint.x
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7357282918100144838, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
|
||||||
|
propertyPath: m_LocalEulerAnglesHint.y
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7357282918100144838, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
|
||||||
|
propertyPath: m_LocalEulerAnglesHint.z
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7357282918100569830, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
|
||||||
|
propertyPath: m_Name
|
||||||
|
value: Skin_1
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7357282918109969512, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
|
||||||
|
propertyPath: m_Controller
|
||||||
|
value:
|
||||||
|
objectReference: {fileID: 9100000, guid: 00743b1e9c8fd4b80b6bd2205c49690a, type: 2}
|
||||||
|
m_RemovedComponents: []
|
||||||
|
m_RemovedGameObjects: []
|
||||||
|
m_AddedGameObjects: []
|
||||||
|
m_AddedComponents: []
|
||||||
|
m_SourcePrefab: {fileID: 100100000, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
|
||||||
--- !u!1 &999347489
|
--- !u!1 &999347489
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -1646,7 +1707,7 @@ PrefabInstance:
|
|||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 1717954561962503726, guid: f6336ac4ac8b4d34bc5072418cdc62a0, type: 3}
|
- target: {fileID: 1717954561962503726, guid: f6336ac4ac8b4d34bc5072418cdc62a0, type: 3}
|
||||||
propertyPath: m_LocalRotation.w
|
propertyPath: m_LocalRotation.w
|
||||||
value: 1
|
value: 0.7531043
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 1717954561962503726, guid: f6336ac4ac8b4d34bc5072418cdc62a0, type: 3}
|
- target: {fileID: 1717954561962503726, guid: f6336ac4ac8b4d34bc5072418cdc62a0, type: 3}
|
||||||
propertyPath: m_LocalRotation.x
|
propertyPath: m_LocalRotation.x
|
||||||
@@ -1654,7 +1715,7 @@ PrefabInstance:
|
|||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 1717954561962503726, guid: f6336ac4ac8b4d34bc5072418cdc62a0, type: 3}
|
- target: {fileID: 1717954561962503726, guid: f6336ac4ac8b4d34bc5072418cdc62a0, type: 3}
|
||||||
propertyPath: m_LocalRotation.y
|
propertyPath: m_LocalRotation.y
|
||||||
value: 0
|
value: -0.65790117
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 1717954561962503726, guid: f6336ac4ac8b4d34bc5072418cdc62a0, type: 3}
|
- target: {fileID: 1717954561962503726, guid: f6336ac4ac8b4d34bc5072418cdc62a0, type: 3}
|
||||||
propertyPath: m_LocalRotation.z
|
propertyPath: m_LocalRotation.z
|
||||||
@@ -1666,7 +1727,7 @@ PrefabInstance:
|
|||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 1717954561962503726, guid: f6336ac4ac8b4d34bc5072418cdc62a0, type: 3}
|
- target: {fileID: 1717954561962503726, guid: f6336ac4ac8b4d34bc5072418cdc62a0, type: 3}
|
||||||
propertyPath: m_LocalEulerAnglesHint.y
|
propertyPath: m_LocalEulerAnglesHint.y
|
||||||
value: 0
|
value: -82.28
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 1717954561962503726, guid: f6336ac4ac8b4d34bc5072418cdc62a0, type: 3}
|
- target: {fileID: 1717954561962503726, guid: f6336ac4ac8b4d34bc5072418cdc62a0, type: 3}
|
||||||
propertyPath: m_LocalEulerAnglesHint.z
|
propertyPath: m_LocalEulerAnglesHint.z
|
||||||
@@ -2482,3 +2543,4 @@ SceneRoots:
|
|||||||
- {fileID: 8676663362647557757}
|
- {fileID: 8676663362647557757}
|
||||||
- {fileID: 1974695068}
|
- {fileID: 1974695068}
|
||||||
- {fileID: 1164055236}
|
- {fileID: 1164055236}
|
||||||
|
- {fileID: 923562640}
|
||||||
|
|||||||
186
Assets/Scripts/EnemyAI.cs
Normal file
186
Assets/Scripts/EnemyAI.cs
Normal file
@@ -0,0 +1,186 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.AI;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
[RequireComponent(typeof(NavMeshAgent))]
|
||||||
|
public class EnemyAI : MonoBehaviour
|
||||||
|
{
|
||||||
|
// 敵の状態を定義する列挙型(FSM)
|
||||||
|
public enum AIState { Wander, Chase }
|
||||||
|
|
||||||
|
[Header("現在の状態")]
|
||||||
|
[SerializeField] private AIState currentState = AIState.Wander;
|
||||||
|
|
||||||
|
[Header("索敵設定")]
|
||||||
|
[Tooltip("プレイヤーを検知する距離")]
|
||||||
|
[SerializeField] private float detectionRange = 10f;
|
||||||
|
[Tooltip("プレイヤーを見失う距離(検知距離より広く設定するのがコツ)")]
|
||||||
|
[SerializeField] private float loseRange = 15f;
|
||||||
|
[Tooltip("プレイヤーのタグ名")]
|
||||||
|
[SerializeField] private string playerTag = "Player";
|
||||||
|
|
||||||
|
[Header("徘徊(Wander)設定")]
|
||||||
|
[SerializeField] private float wanderRadius = 8f;
|
||||||
|
[SerializeField] private float minWaitTime = 0.1f;
|
||||||
|
[SerializeField] private float maxWaitTime = 1f;
|
||||||
|
|
||||||
|
[Tooltip("目的地に向けて移動を開始してから、何秒で諦めるか")]
|
||||||
|
[SerializeField] private float wanderTimeout = 7f;
|
||||||
|
|
||||||
|
private NavMeshAgent agent;
|
||||||
|
private Transform playerTransform;
|
||||||
|
private bool isWandering = false;
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
agent = GetComponent<NavMeshAgent>();
|
||||||
|
|
||||||
|
// 負荷軽減のため、AIの思考ループをコルーチンで開始(毎フレーム Update で処理しない)
|
||||||
|
StartCoroutine(AILoop());
|
||||||
|
}
|
||||||
|
|
||||||
|
// AIの意思決定を行うメインループ(0.2秒ごとに実行して負荷を劇的に下げる)
|
||||||
|
private IEnumerator AILoop()
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
// 1. プレイヤーを探す(まだ見つけていない場合のみ)
|
||||||
|
if (playerTransform == null)
|
||||||
|
{
|
||||||
|
FindPlayer();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 現在のステート(状態)に応じて処理を分岐
|
||||||
|
switch (currentState)
|
||||||
|
{
|
||||||
|
case AIState.Wander:
|
||||||
|
WanderBehavior();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AIState.Chase:
|
||||||
|
ChaseBehavior();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 毎フレームではなく、0.2秒(1秒に5回)だけ実行する(Quest 3向けの最適化)
|
||||||
|
yield return new WaitForSeconds(0.2f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// シーン内からプレイヤー(タグ付き)を探すメソッド
|
||||||
|
private void FindPlayer()
|
||||||
|
{
|
||||||
|
GameObject playerObj = GameObject.FindGameObjectWithTag(playerTag);
|
||||||
|
if (playerObj != null)
|
||||||
|
{
|
||||||
|
playerTransform = playerObj.transform;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── 【徘徊状態】の行動 ───
|
||||||
|
private void WanderBehavior()
|
||||||
|
{
|
||||||
|
if (playerTransform != null)
|
||||||
|
{
|
||||||
|
// プレイヤーとの距離を計算
|
||||||
|
float distanceToPlayer = Vector3.Distance(transform.position, playerTransform.position);
|
||||||
|
|
||||||
|
// 索敵範囲内に入ったら「追跡状態」へ遷移
|
||||||
|
if (distanceToPlayer <= detectionRange)
|
||||||
|
{
|
||||||
|
currentState = AIState.Chase;
|
||||||
|
isWandering = false;
|
||||||
|
agent.ResetPath(); // 徘徊の目的地をリセット
|
||||||
|
Debug.Log($"👁️ {gameObject.name}: プレイヤーを発見! 追跡します。");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 徘徊の移動ロジック
|
||||||
|
if (!isWandering)
|
||||||
|
{
|
||||||
|
StartCoroutine(WanderMoveRoutine());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerator WanderMoveRoutine()
|
||||||
|
{
|
||||||
|
isWandering = true;
|
||||||
|
|
||||||
|
// ランダムな目的地を取得して移動開始
|
||||||
|
Vector3 newPos = GetRandomNavMeshPoint(transform.position, wanderRadius);
|
||||||
|
agent.SetDestination(newPos);
|
||||||
|
|
||||||
|
float elapsedTime = 0f; // 経過時間を計るカウンター
|
||||||
|
|
||||||
|
// 目的地に到着するまで待つ(ただしタイムアウト時間を超えたらループを抜ける)
|
||||||
|
while (agent.remainingDistance > agent.stoppingDistance)
|
||||||
|
{
|
||||||
|
// 0.5秒ごとにチェック
|
||||||
|
yield return new WaitForSeconds(0.5f);
|
||||||
|
elapsedTime += 0.5f;
|
||||||
|
|
||||||
|
// 【スタック対策】設定した制限時間を超えた場合
|
||||||
|
if (elapsedTime >= wanderTimeout)
|
||||||
|
{
|
||||||
|
Debug.Log($"⚠️ {gameObject.name}: 目的地({newPos})に到達できないため諦めました。");
|
||||||
|
|
||||||
|
agent.ResetPath(); // 動けない経路(バグ目的地)を一旦クリアする
|
||||||
|
break; // whileループを強制終了して次の目的地設定へ進める
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 到着後(または諦めた後)、ランダムな時間だけその場で待機して次の徘徊へ
|
||||||
|
yield return new WaitForSeconds(Random.Range(minWaitTime, maxWaitTime));
|
||||||
|
isWandering = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── 【追跡状態】の行動 ───
|
||||||
|
private void ChaseBehavior()
|
||||||
|
{
|
||||||
|
if (playerTransform == null)
|
||||||
|
{
|
||||||
|
currentState = AIState.Wander;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
float distanceToPlayer = Vector3.Distance(transform.position, playerTransform.position);
|
||||||
|
|
||||||
|
// 見失う距離(loseRange)を超えたら「徘徊状態」に戻る
|
||||||
|
if (distanceToPlayer > loseRange)
|
||||||
|
{
|
||||||
|
currentState = AIState.Wander;
|
||||||
|
agent.ResetPath();
|
||||||
|
Debug.Log($"❓ {gameObject.name}: プレイヤーを見失った。徘徊に戻ります。");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// プレイヤーの位置を目的地に設定(0.2秒ごとに更新されるため、滑らかに追従します)
|
||||||
|
agent.SetDestination(playerTransform.position);
|
||||||
|
}
|
||||||
|
|
||||||
|
// NavMesh上のランダムな座標を取得する補助メソッド
|
||||||
|
private Vector3 GetRandomNavMeshPoint(Vector3 center, float radius)
|
||||||
|
{
|
||||||
|
Vector3 randomDirection = Random.insideUnitSphere * radius;
|
||||||
|
randomDirection += center;
|
||||||
|
NavMeshHit hit;
|
||||||
|
if (NavMesh.SamplePosition(randomDirection, out hit, radius, NavMesh.AllAreas))
|
||||||
|
{
|
||||||
|
return hit.position;
|
||||||
|
}
|
||||||
|
return center;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 【視覚的なデバッグ用】エディタ上で索敵範囲を線で表示する
|
||||||
|
private void OnDrawGizmosSelected()
|
||||||
|
{
|
||||||
|
// 索敵範囲(赤)
|
||||||
|
Gizmos.color = Color.red;
|
||||||
|
Gizmos.DrawWireSphere(transform.position, detectionRange);
|
||||||
|
|
||||||
|
// 見失う範囲(黄)
|
||||||
|
Gizmos.color = Color.yellow;
|
||||||
|
Gizmos.DrawWireSphere(transform.position, loseRange);
|
||||||
|
}
|
||||||
|
}
|
||||||
2
Assets/Scripts/EnemyAI.cs.meta
Normal file
2
Assets/Scripts/EnemyAI.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 88407b9f9a6654436b641cce64611731
|
||||||
@@ -521,18 +521,8 @@ MonoBehaviour:
|
|||||||
features:
|
features:
|
||||||
- {fileID: 8736661028334727731}
|
- {fileID: 8736661028334727731}
|
||||||
- {fileID: 3598254934845347770}
|
- {fileID: 3598254934845347770}
|
||||||
- {fileID: 6956056911768161135}
|
|
||||||
- {fileID: -6387251413244805544}
|
|
||||||
- {fileID: 1170704673688743257}
|
- {fileID: 1170704673688743257}
|
||||||
- {fileID: -1187533949232362847}
|
|
||||||
- {fileID: -949347770443697596}
|
|
||||||
- {fileID: -1529727133502117446}
|
|
||||||
- {fileID: 5153017048313567732}
|
- {fileID: 5153017048313567732}
|
||||||
- {fileID: 265326132771859475}
|
|
||||||
- {fileID: 2834828863856360103}
|
|
||||||
- {fileID: -2851827796942056979}
|
|
||||||
- {fileID: -8128959895479975907}
|
|
||||||
- {fileID: -142859899272520151}
|
|
||||||
- {fileID: 6481653220666705815}
|
- {fileID: 6481653220666705815}
|
||||||
- {fileID: 7393116930172532905}
|
- {fileID: 7393116930172532905}
|
||||||
- {fileID: 744375598501864353}
|
- {fileID: 744375598501864353}
|
||||||
@@ -1531,7 +1521,7 @@ MonoBehaviour:
|
|||||||
nameUi: 'Android XR: AR Anchor'
|
nameUi: 'Android XR: AR Anchor'
|
||||||
version: 0.1.0
|
version: 0.1.0
|
||||||
featureIdInternal: com.unity.openxr.feature.arfoundation-androidxr-anchor
|
featureIdInternal: com.unity.openxr.feature.arfoundation-androidxr-anchor
|
||||||
openxrExtensionStrings: XR_ANDROID_trackables
|
openxrExtensionStrings: XR_ANDROID_trackables XR_ANDROID_device_anchor_persistence
|
||||||
company: Unity Technologies
|
company: Unity Technologies
|
||||||
priority: 0
|
priority: 0
|
||||||
targetOpenXRApiVersion:
|
targetOpenXRApiVersion:
|
||||||
@@ -2453,7 +2443,7 @@ MonoBehaviour:
|
|||||||
nameUi: 'Android XR: AR Anchor'
|
nameUi: 'Android XR: AR Anchor'
|
||||||
version: 0.1.0
|
version: 0.1.0
|
||||||
featureIdInternal: com.unity.openxr.feature.arfoundation-androidxr-anchor
|
featureIdInternal: com.unity.openxr.feature.arfoundation-androidxr-anchor
|
||||||
openxrExtensionStrings: XR_ANDROID_trackables
|
openxrExtensionStrings: XR_ANDROID_trackables XR_ANDROID_device_anchor_persistence
|
||||||
company: Unity Technologies
|
company: Unity Technologies
|
||||||
priority: 0
|
priority: 0
|
||||||
targetOpenXRApiVersion:
|
targetOpenXRApiVersion:
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"com.unity.ai.navigation": "2.0.12",
|
||||||
"com.unity.feature.development": "1.0.2",
|
"com.unity.feature.development": "1.0.2",
|
||||||
"com.unity.ide.rider": "3.0.39",
|
"com.unity.ide.rider": "3.0.39",
|
||||||
"com.unity.inputsystem": "1.17.0",
|
"com.unity.inputsystem": "1.17.0",
|
||||||
|
|||||||
@@ -1,5 +1,14 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"com.unity.ai.navigation": {
|
||||||
|
"version": "2.0.12",
|
||||||
|
"depth": 0,
|
||||||
|
"source": "registry",
|
||||||
|
"dependencies": {
|
||||||
|
"com.unity.modules.ai": "1.0.0"
|
||||||
|
},
|
||||||
|
"url": "https://packages.unity.com"
|
||||||
|
},
|
||||||
"com.unity.burst": {
|
"com.unity.burst": {
|
||||||
"version": "1.8.27",
|
"version": "1.8.27",
|
||||||
"depth": 2,
|
"depth": 2,
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ TagManager:
|
|||||||
-
|
-
|
||||||
- Water
|
- Water
|
||||||
- UI
|
- UI
|
||||||
-
|
- Floor
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
|
|||||||
Reference in New Issue
Block a user