放置障礙物,優化玩家尋找敵方方式

This commit is contained in:
Sahik committed 2026-10-21 06:11:30 +08:00
1 parent f07d687be8
commit c644491e93
14 files changed
+2517 -26

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

@@ -0,0 +1,130 @@
fileFormatVersion: 2
guid: 1ee3d76369ff40b4481167439c35e747
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 13
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 0
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 4
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
customData:
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spriteCustomMetadata:
entries: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:
+4 -4
View File
@@ -125,14 +125,14 @@ MonoBehaviour:
<CapsuleCollider>k__BackingField: {fileID: 7901344025037588819}
<PlayerAnimator>k__BackingField: {fileID: 0}
<MotorSettings>k__BackingField: {fileID: 0}
<Speed>k__BackingField: 5
<Speed>k__BackingField: 4.4
<WalkSpeed>k__BackingField: 2.2
<GroundAcceleration>k__BackingField: 45
<GroundDeceleration>k__BackingField: 55
<RotationDamping>k__BackingField: 12
<AllowSprint>k__BackingField: 1
<SprintActivation>k__BackingField: 0
<SprintSpeed>k__BackingField: 8
<SprintSpeed>k__BackingField: 6.6
<AllowJump>k__BackingField: 1
<JumpingForce>k__BackingField: 6.5
<VariableJumpHeight>k__BackingField: 1
@@ -149,7 +149,7 @@ MonoBehaviour:
<MaxFallSpeed>k__BackingField: 30
<AllowCrouch>k__BackingField: 1
<AllowProne>k__BackingField: 1
<CrouchSpeed>k__BackingField: 2.4
<CrouchSpeed>k__BackingField: 2
<ProneSpeed>k__BackingField: 1.2
<CrouchCapsuleHeight>k__BackingField: 1.15
<ProneCapsuleHeight>k__BackingField: 0.55
@@ -466,7 +466,7 @@ CapsuleCollider:
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 2
m_Radius: 0.2
m_Radius: 0.25
m_Height: 0.66
m_Direction: 1
m_Center: {x: 0, y: -0.03, z: 0}
@@ -6,7 +6,7 @@ TextureImporter:
serializedVersion: 13
mipmaps:
mipMapMode: 0
enableMipMap: 1
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
@@ -37,13 +37,13 @@ TextureImporter:
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapU: 1
wrapV: 1
wrapW: 0
nPOTScale: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
@@ -52,9 +52,9 @@ TextureImporter:
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 0
textureType: 8
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
@@ -113,7 +113,7 @@ TextureImporter:
customData:
physicsShape: []
bones: []
spriteID:
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 34a0477164bb0a44b98e0c0c0184dbb4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,137 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &-7769585698315732740
MonoBehaviour:
m_ObjectHideFlags: 11
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
m_Name:
m_EditorClassIdentifier: Unity.RenderPipelines.Universal.Editor::UnityEditor.Rendering.Universal.AssetVersion
version: 10
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: texture_01
m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap:
RenderType: Opaque
disabledShaderPasses:
- MOTIONVECTORS
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BaseMap:
m_Texture: {fileID: 2800000, guid: 4e5ce0456eaa517409a465cbcd1639f2, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 2800000, guid: 4e5ce0456eaa517409a465cbcd1639f2, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SpecGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_Lightmaps:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_LightmapsInd:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_ShadowMasks:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _AddPrecomputedVelocity: 0
- _AlphaClip: 0
- _AlphaToMask: 0
- _Blend: 0
- _BlendModePreserveSpecular: 1
- _BumpScale: 1
- _ClearCoatMask: 0
- _ClearCoatSmoothness: 0
- _Cull: 2
- _Cutoff: 0.5
- _DetailAlbedoMapScale: 1
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _DstBlendAlpha: 0
- _EnvironmentReflections: 1
- _GlossMapScale: 0
- _Glossiness: 0
- _GlossyReflections: 0
- _Metallic: 0
- _OcclusionStrength: 1
- _Parallax: 0.005
- _QueueOffset: 0
- _ReceiveShadows: 1
- _Smoothness: 0.5
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _SrcBlendAlpha: 1
- _Surface: 0
- _WorkflowMode: 1
- _XRMotionVectorsPass: 1
- _ZWrite: 1
m_Colors:
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
m_BuildTextureStacks: []
m_AllowLocking: 1
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fcac5b743fc78c24f856546a9203c33d
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:
@@ -6,7 +6,7 @@ TextureImporter:
serializedVersion: 13
mipmaps:
mipMapMode: 0
enableMipMap: 1
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
@@ -37,13 +37,13 @@ TextureImporter:
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapU: 1
wrapV: 1
wrapW: 0
nPOTScale: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
@@ -52,9 +52,9 @@ TextureImporter:
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 0
textureType: 8
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
@@ -113,7 +113,7 @@ TextureImporter:
customData:
physicsShape: []
bones: []
spriteID:
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
+2115 -3
View File
File diff suppressed because it is too large. Load diff
+18 -3
View File
@@ -23,6 +23,9 @@ public class BotSpawner : MonoBehaviour
[Tooltip("倒下後多久生成下一隻 (秒)")]
public float respawnDelay = 1.5f;
// 目前活著的機器人,倒下到重生之間是 null (給方位指示等 UI 用)
public BotHealth CurrentBot { get; private set; }
void Start()
{
Spawn();
@@ -40,12 +43,14 @@ public class BotSpawner : MonoBehaviour
if (bot.TryGetComponent(out BotHealth health))
{
health.Died += OnBotDied;
CurrentBot = health;
}
}
void OnBotDied(BotHealth bot)
{
bot.Died -= OnBotDied;
CurrentBot = null;
StartCoroutine(RespawnAfterDelay());
}
@@ -55,17 +60,18 @@ public class BotSpawner : MonoBehaviour
Spawn();
}
// 在範圍內隨機選點,盡量離玩家遠一點 ; 試幾次都太近就用最後一次的結果
// 在範圍內隨機選點 : 要離玩家夠遠,而且不能卡在障礙物或牆裡 ; 試很多次都不行就用最後一次的結果
Vector3 PickSpawnPoint()
{
Vector3 point = transform.position;
for (int i = 0; i < 20; i++)
for (int i = 0; i < 50; i++)
{
Vector2 offset = Random.insideUnitCircle * spawnRadius;
point = transform.position + new Vector3(offset.x, 0f, offset.y);
if (player == null || Vector3.Distance(point, player.position) >= minDistanceFromPlayer)
bool farEnough = player == null || Vector3.Distance(point, player.position) >= minDistanceFromPlayer;
if (farEnough && IsSpaceFree(point))
{
break;
}
@@ -74,6 +80,15 @@ public class BotSpawner : MonoBehaviour
return point;
}
// 用一個跟機器人差不多大的膠囊檢查這個位置有沒有東西 ; 底部抬高一點,不去碰到地板
bool IsSpaceFree(Vector3 feet)
{
const float radius = 0.4f;
Vector3 bottom = feet + Vector3.up * (radius + 0.1f);
Vector3 top = feet + Vector3.up * (1.8f - radius);
return !Physics.CheckCapsule(bottom, top, radius, ~0, QueryTriggerInteraction.Ignore);
}
// 在 Scene 視窗畫出生成範圍,方便調整
void OnDrawGizmosSelected()
{
+44
View File
@@ -0,0 +1,44 @@
using UnityEngine;
// 敵人血條 : 裡面那條會依剩餘血量縮短,左邊固定、從右邊往左扣
public class EnemyHealthBar : MonoBehaviour
{
[Header("參照")]
public BotSpawner spawner;
[Tooltip("整個血條 (外框),沒有敵人時隱藏")]
public GameObject panel;
[Tooltip("會縮短的那條 (外框裡面的 Image)")]
public RectTransform fill;
private float fullWidth;
private float centerX;
private float shownRatio = -1f;
void Awake()
{
if (fill != null)
{
fullWidth = fill.sizeDelta.x;
centerX = fill.anchoredPosition.x;
}
}
void Update()
{
// 機器人倒下到重生之間先隱藏
BotHealth bot = spawner != null ? spawner.CurrentBot : null;
if (panel != null) panel.SetActive(bot != null);
if (bot == null || fill == null) return;
float ratio = bot.maxHealth > 0f ? Mathf.Clamp01(bot.Health / bot.maxHealth) : 0f;
if (Mathf.Approximately(ratio, shownRatio)) return;
shownRatio = ratio;
// 寬度照比例縮短,再依 Pivot 往左移,讓左邊維持在原位
float width = fullWidth * ratio;
fill.sizeDelta = new Vector2(width, fill.sizeDelta.y);
fill.anchoredPosition = new Vector2(centerX - fill.pivot.x * (fullWidth - width), fill.anchoredPosition.y);
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: f20c2b1f45472084cbc13187b05e9d8d
+33
View File
@@ -0,0 +1,33 @@
using UnityEngine;
// 敵人方位指示 : 箭頭轉向敵人所在的水平方向
// 箭頭圖片朝上 = 敵人在正前方 ; 敵人在右邊時箭頭往右轉
public class EnemyIndicator : MonoBehaviour
{
[Header("參照")]
public BotSpawner spawner;
[Tooltip("Main Camera,以它的朝向為基準")]
public Camera viewCamera;
[Tooltip("箭頭 (朝上的圖片)")]
public RectTransform pointer;
void Update()
{
if (pointer == null) return;
// 機器人倒下到重生之間先隱藏
BotHealth bot = spawner != null ? spawner.CurrentBot : null;
bool hasTarget = bot != null && viewCamera != null;
pointer.gameObject.SetActive(hasTarget);
if (!hasTarget) return;
// 只看水平方向 : 正數 = 敵人在右邊,負數 = 在左邊
Vector3 forward = Vector3.ProjectOnPlane(viewCamera.transform.forward, Vector3.up);
Vector3 toBot = Vector3.ProjectOnPlane(bot.transform.position - viewCamera.transform.position, Vector3.up);
float angle = Vector3.SignedAngle(forward, toBot, Vector3.up);
pointer.localEulerAngles = new Vector3(0f, 0f, -angle); // UI 的 Z 軸是逆時針,所以取負號
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 057ccc4b1126d6d4aa881bc4633338b8