발판 추적시스템 수정
This commit is contained in:
parent
895174a046
commit
a9cd1eccaf
|
|
@ -13,7 +13,7 @@ GameObject:
|
||||||
- component: {fileID: 2323667017725586191}
|
- component: {fileID: 2323667017725586191}
|
||||||
- component: {fileID: 8967009380059366119}
|
- component: {fileID: 8967009380059366119}
|
||||||
- component: {fileID: 7290293607820690937}
|
- component: {fileID: 7290293607820690937}
|
||||||
m_Layer: 6
|
m_Layer: 7
|
||||||
m_Name: Block
|
m_Name: Block
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
m_Icon: {fileID: 0}
|
m_Icon: {fileID: 0}
|
||||||
|
|
@ -138,6 +138,7 @@ MonoBehaviour:
|
||||||
- {fileID: 8470849048189565944, guid: 07676f3c42557424c82b5586340089b9, type: 3}
|
- {fileID: 8470849048189565944, guid: 07676f3c42557424c82b5586340089b9, type: 3}
|
||||||
debrisCount: 3
|
debrisCount: 3
|
||||||
explosionForce: 1
|
explosionForce: 1
|
||||||
|
debrisLifetime: 2
|
||||||
--- !u!61 &7290293607820690937
|
--- !u!61 &7290293607820690937
|
||||||
BoxCollider2D:
|
BoxCollider2D:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
|
||||||
|
|
@ -5,34 +5,48 @@ public class DestructibleBlock : Entity
|
||||||
[SerializeField] private GameObject[] debrisPrefabs;
|
[SerializeField] private GameObject[] debrisPrefabs;
|
||||||
[SerializeField] private int debrisCount = 5;
|
[SerializeField] private int debrisCount = 5;
|
||||||
[SerializeField] private float explosionForce = 5f;
|
[SerializeField] private float explosionForce = 5f;
|
||||||
|
[SerializeField] private float debrisLifetime = 2f;
|
||||||
|
|
||||||
public override void TakeDamage(int damage)
|
protected override void Die()
|
||||||
{
|
|
||||||
base.TakeDamage(damage);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnDestroy()
|
|
||||||
{
|
{
|
||||||
SpawnDebris();
|
SpawnDebris();
|
||||||
|
base.Die();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnCollisionEnter2D(Collision2D collision)
|
||||||
|
{
|
||||||
|
if (collision.gameObject.CompareTag("Player"))
|
||||||
|
{
|
||||||
|
Player player = collision.gameObject.GetComponent<Player>();
|
||||||
|
if (player != null && player.IsDashing())
|
||||||
|
{
|
||||||
|
Die();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SpawnDebris()
|
private void SpawnDebris()
|
||||||
{
|
{
|
||||||
|
if (debrisPrefabs == null || debrisPrefabs.Length == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < debrisCount; i++)
|
for (int i = 0; i < debrisCount; i++)
|
||||||
{
|
{
|
||||||
|
Vector2 spawnPos = (Vector2)transform.position + Random.insideUnitCircle * 0.5f;
|
||||||
GameObject prefab = debrisPrefabs[Random.Range(0, debrisPrefabs.Length)];
|
GameObject prefab = debrisPrefabs[Random.Range(0, debrisPrefabs.Length)];
|
||||||
Vector2 randomPos = (Vector2)transform.position + Random.insideUnitCircle * 0.5f;
|
GameObject debris = Instantiate(prefab, spawnPos, Quaternion.identity);
|
||||||
GameObject debris = Instantiate(prefab, randomPos, Quaternion.identity);
|
|
||||||
Rigidbody2D rb = debris.GetComponent<Rigidbody2D>();
|
Rigidbody2D rb = debris.GetComponent<Rigidbody2D>();
|
||||||
|
|
||||||
if (rb != null)
|
if (rb != null)
|
||||||
{
|
{
|
||||||
Vector2 dir = (randomPos - (Vector2)transform.position).normalized;
|
Vector2 dir = (spawnPos - (Vector2)transform.position).normalized;
|
||||||
dir += Random.insideUnitCircle * 0.5f;
|
dir += Random.insideUnitCircle * 0.5f;
|
||||||
rb.AddForce(dir.normalized * explosionForce, ForceMode2D.Impulse);
|
rb.AddForce(dir.normalized * explosionForce, ForceMode2D.Impulse);
|
||||||
|
rb.AddTorque(Random.Range(-180f, 180f));
|
||||||
}
|
}
|
||||||
|
|
||||||
Destroy(debris, 2f);
|
Destroy(debris, debrisLifetime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
156
Assets/Block/Trap.prefab
Normal file
156
Assets/Block/Trap.prefab
Normal file
|
|
@ -0,0 +1,156 @@
|
||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!1 &2025971683497085228
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 6964338176317010345}
|
||||||
|
- component: {fileID: 5109637665812112634}
|
||||||
|
- component: {fileID: 4845338078289388792}
|
||||||
|
- component: {fileID: 8311574796361930648}
|
||||||
|
m_Layer: 3
|
||||||
|
m_Name: Trap
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &6964338176317010345
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2025971683497085228}
|
||||||
|
serializedVersion: 2
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: -0.5, y: 1.5, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!212 &5109637665812112634
|
||||||
|
SpriteRenderer:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2025971683497085228}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_CastShadows: 0
|
||||||
|
m_ReceiveShadows: 0
|
||||||
|
m_DynamicOccludee: 1
|
||||||
|
m_StaticShadowCaster: 0
|
||||||
|
m_MotionVectors: 1
|
||||||
|
m_LightProbeUsage: 1
|
||||||
|
m_ReflectionProbeUsage: 1
|
||||||
|
m_RayTracingMode: 0
|
||||||
|
m_RayTraceProcedural: 0
|
||||||
|
m_RayTracingAccelStructBuildFlagsOverride: 0
|
||||||
|
m_RayTracingAccelStructBuildFlags: 1
|
||||||
|
m_SmallMeshCulling: 1
|
||||||
|
m_ForceMeshLod: -1
|
||||||
|
m_MeshLodSelectionBias: 0
|
||||||
|
m_RenderingLayerMask: 1
|
||||||
|
m_RendererPriority: 0
|
||||||
|
m_Materials:
|
||||||
|
- {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2}
|
||||||
|
m_StaticBatchInfo:
|
||||||
|
firstSubMesh: 0
|
||||||
|
subMeshCount: 0
|
||||||
|
m_StaticBatchRoot: {fileID: 0}
|
||||||
|
m_ProbeAnchor: {fileID: 0}
|
||||||
|
m_LightProbeVolumeOverride: {fileID: 0}
|
||||||
|
m_ScaleInLightmap: 1
|
||||||
|
m_ReceiveGI: 1
|
||||||
|
m_PreserveUVs: 0
|
||||||
|
m_IgnoreNormalsForChartDetection: 0
|
||||||
|
m_ImportantGI: 0
|
||||||
|
m_StitchLightmapSeams: 1
|
||||||
|
m_SelectedEditorRenderState: 0
|
||||||
|
m_MinimumChartSize: 4
|
||||||
|
m_AutoUVMaxDistance: 0.5
|
||||||
|
m_AutoUVMaxAngle: 89
|
||||||
|
m_LightmapParameters: {fileID: 0}
|
||||||
|
m_GlobalIlluminationMeshLod: 0
|
||||||
|
m_SortingLayerID: 0
|
||||||
|
m_SortingLayer: 0
|
||||||
|
m_SortingOrder: 0
|
||||||
|
m_MaskInteraction: 0
|
||||||
|
m_Sprite: {fileID: -855298285791758126, guid: 9fc32b26c4b0b87459965e872a8507d2, type: 3}
|
||||||
|
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
m_FlipX: 0
|
||||||
|
m_FlipY: 0
|
||||||
|
m_DrawMode: 0
|
||||||
|
m_Size: {x: 1, y: 1}
|
||||||
|
m_AdaptiveModeThreshold: 0.5
|
||||||
|
m_SpriteTileMode: 0
|
||||||
|
m_WasSpriteAssigned: 1
|
||||||
|
m_SpriteSortPoint: 0
|
||||||
|
--- !u!114 &4845338078289388792
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2025971683497085228}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: c81c9e0030ef823459d0d8a8f6a159e5, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier: Assembly-CSharp::TrapBlock
|
||||||
|
damage: 10
|
||||||
|
activationTime: 2
|
||||||
|
damageInterval: 1
|
||||||
|
--- !u!61 &8311574796361930648
|
||||||
|
BoxCollider2D:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2025971683497085228}
|
||||||
|
m_Enabled: 1
|
||||||
|
serializedVersion: 3
|
||||||
|
m_Density: 1
|
||||||
|
m_Material: {fileID: 0}
|
||||||
|
m_IncludeLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 0
|
||||||
|
m_ExcludeLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 0
|
||||||
|
m_LayerOverridePriority: 0
|
||||||
|
m_ForceSendLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 4294967295
|
||||||
|
m_ForceReceiveLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 4294967295
|
||||||
|
m_ContactCaptureLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 4294967295
|
||||||
|
m_CallbackLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 4294967295
|
||||||
|
m_IsTrigger: 0
|
||||||
|
m_UsedByEffector: 0
|
||||||
|
m_CompositeOperation: 0
|
||||||
|
m_CompositeOrder: 0
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
m_SpriteTilingProperty:
|
||||||
|
border: {x: 0, y: 0, z: 0, w: 0}
|
||||||
|
pivot: {x: 0.5, y: 0.5}
|
||||||
|
oldSize: {x: 1, y: 1}
|
||||||
|
newSize: {x: 1, y: 1}
|
||||||
|
adaptiveTilingThreshold: 0.5
|
||||||
|
drawMode: 0
|
||||||
|
adaptiveTiling: 0
|
||||||
|
m_AutoTiling: 0
|
||||||
|
m_Size: {x: 1, y: 1}
|
||||||
|
m_EdgeRadius: 0
|
||||||
7
Assets/Block/Trap.prefab.meta
Normal file
7
Assets/Block/Trap.prefab.meta
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c1e04369fcd95764abcbb1a9fd356bde
|
||||||
|
PrefabImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
|
@ -1,6 +1,47 @@
|
||||||
|
using System.Collections;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class TrapBlock : MonoBehaviour
|
public class TrapBlock : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
[SerializeField] private int damage = 10;
|
||||||
|
[SerializeField] private float activationTime = 2f;
|
||||||
|
[SerializeField] private float damageInterval = 1f;
|
||||||
|
|
||||||
|
private Coroutine trapCoroutine;
|
||||||
|
|
||||||
|
private void OnCollisionEnter2D(Collision2D collision)
|
||||||
|
{
|
||||||
|
if (collision.gameObject.CompareTag("Player"))
|
||||||
|
{
|
||||||
|
Player player = collision.gameObject.GetComponent<Player>();
|
||||||
|
if (player != null)
|
||||||
|
{
|
||||||
|
if (trapCoroutine != null)
|
||||||
|
{
|
||||||
|
StopCoroutine(trapCoroutine);
|
||||||
|
}
|
||||||
|
|
||||||
|
trapCoroutine = StartCoroutine(ProcessTrapDamage(player));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnCollisionExit2D(Collision2D collision)
|
||||||
|
{
|
||||||
|
if (collision.gameObject.CompareTag("Player"))
|
||||||
|
{
|
||||||
|
StopCoroutine(trapCoroutine);
|
||||||
|
trapCoroutine = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerator ProcessTrapDamage(Player player)
|
||||||
|
{
|
||||||
|
yield return new WaitForSeconds(activationTime);
|
||||||
|
while (player != null)
|
||||||
|
{
|
||||||
|
player.TakeDamage(damage);
|
||||||
|
yield return new WaitForSeconds(damageInterval);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -11,7 +11,6 @@ GameObject:
|
||||||
- component: {fileID: 3182903703610233758}
|
- component: {fileID: 3182903703610233758}
|
||||||
- component: {fileID: 3818235801779510969}
|
- component: {fileID: 3818235801779510969}
|
||||||
- component: {fileID: 3096000554608240826}
|
- component: {fileID: 3096000554608240826}
|
||||||
- component: {fileID: 4449206212094151330}
|
|
||||||
m_Layer: 6
|
m_Layer: 6
|
||||||
m_Name: TestEntity
|
m_Name: TestEntity
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
|
|
@ -139,22 +138,3 @@ BoxCollider2D:
|
||||||
m_AutoTiling: 0
|
m_AutoTiling: 0
|
||||||
m_Size: {x: 1, y: 1}
|
m_Size: {x: 1, y: 1}
|
||||||
m_EdgeRadius: 0
|
m_EdgeRadius: 0
|
||||||
--- !u!114 &4449206212094151330
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 3345230653483034275}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: 3eada057783728046bc1f3df10f17294, type: 3}
|
|
||||||
m_Name:
|
|
||||||
m_EditorClassIdentifier: Assembly-CSharp::Entity
|
|
||||||
OnDeath:
|
|
||||||
m_PersistentCalls:
|
|
||||||
m_Calls: []
|
|
||||||
OnTakeDamage:
|
|
||||||
m_PersistentCalls:
|
|
||||||
m_Calls: []
|
|
||||||
data: {fileID: 11400000, guid: a5edb67c4940a4e4692478c7267fc1f8, type: 2}
|
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,5 +1,5 @@
|
||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 1f477f6b90a7bde409fd49711c61b0d6
|
guid: 66251bf89c540684597e665280210ffb
|
||||||
folderAsset: yes
|
folderAsset: yes
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
16
Assets/Scripts/Item/Item.cs
Normal file
16
Assets/Scripts/Item/Item.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class NewMonoBehaviourScript : MonoBehaviour
|
||||||
|
{
|
||||||
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
2
Assets/Scripts/Item/Item.cs.meta
Normal file
2
Assets/Scripts/Item/Item.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4c920d8c33f050549989daf15e771bf2
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 1f477f6b90a7bde409fd49711c61b0d6
|
guid: 24abfdeea51026848bbc59f4654e211b
|
||||||
folderAsset: yes
|
folderAsset: yes
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
|
|
|
||||||
22
Assets/Scripts/Monster/EnemyHitbox.cs
Normal file
22
Assets/Scripts/Monster/EnemyHitbox.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class EnemyHitbox : MonoBehaviour
|
||||||
|
{
|
||||||
|
private Entity owner;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
owner = GetComponentInParent<Entity>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTriggerEnter2D(Collider2D other)
|
||||||
|
{
|
||||||
|
Player player = other.GetComponent<Player>();
|
||||||
|
if (player == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
owner.OnHitPlayer(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
2
Assets/Scripts/Monster/EnemyHitbox.cs.meta
Normal file
2
Assets/Scripts/Monster/EnemyHitbox.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ba177d4337a6fb748b2d22b71512d6a5
|
||||||
|
|
@ -3,45 +3,52 @@ using UnityEngine.Events;
|
||||||
|
|
||||||
public class Entity : MonoBehaviour
|
public class Entity : MonoBehaviour
|
||||||
{
|
{
|
||||||
private int maxHp;
|
protected int maxHp;
|
||||||
private int currentHp;
|
protected int currentHp;
|
||||||
private int attackDamage;
|
protected int attackDamage;
|
||||||
|
|
||||||
[SerializeField] private EntityData data;
|
[SerializeField] protected EntityData data;
|
||||||
|
|
||||||
void Awake()
|
protected virtual void Awake()
|
||||||
|
{
|
||||||
|
if (data != null)
|
||||||
{
|
{
|
||||||
maxHp = data.maxHealth;
|
maxHp = data.maxHealth;
|
||||||
currentHp = data.maxHealth;
|
currentHp = data.maxHealth;
|
||||||
attackDamage = data.attackDamage;
|
attackDamage = data.attackDamage;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void TakeDamage(int playerAttackDamage)
|
public virtual void TakeDamage(int damage)
|
||||||
{
|
{
|
||||||
currentHp -= playerAttackDamage;
|
currentHp -= damage;
|
||||||
|
|
||||||
if (currentHp <= 0)
|
if (currentHp <= 0)
|
||||||
|
{
|
||||||
|
Die();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void Die()
|
||||||
{
|
{
|
||||||
currentHp = 0;
|
currentHp = 0;
|
||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void OnTriggerEnter2D(Collider2D other)
|
public virtual void OnHitPlayer(Player player)
|
||||||
{
|
{
|
||||||
if (other.CompareTag("Player"))
|
|
||||||
{
|
|
||||||
other.gameObject.GetComponent<Player>().TakeDamage(attackDamage);
|
|
||||||
Destroy(gameObject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Update()
|
player.TakeDamage(attackDamage);
|
||||||
{
|
Die();
|
||||||
this.RunAI();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void RunAI()
|
public virtual void RunAI()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
RunAI();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,21 +1,16 @@
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.AI;
|
|
||||||
|
|
||||||
public class FlyEnemyMovement : Entity
|
public class FlyEnemyMovement : Entity
|
||||||
{
|
{
|
||||||
|
[SerializeField] private float detectionRange = 8.0f;
|
||||||
|
[SerializeField] private float moveSpeed = 3.0f;
|
||||||
|
[SerializeField] private LayerMask obstacleLayer;
|
||||||
|
|
||||||
private GameObject playerObject;
|
private GameObject playerObject;
|
||||||
private NavMeshAgent agent;
|
|
||||||
|
|
||||||
[SerializeField] private float detectionRange = 5.0f; // 감지 범위 변수
|
protected override void Awake()
|
||||||
[SerializeField] private float EnemyTime;
|
|
||||||
|
|
||||||
private void Awake()
|
|
||||||
{
|
{
|
||||||
agent = GetComponent<NavMeshAgent>();
|
base.Awake();
|
||||||
|
|
||||||
// NavMeshPlus 2D 설정
|
|
||||||
agent.updateRotation = false;
|
|
||||||
agent.updateUpAxis = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
|
|
@ -27,33 +22,32 @@ public class FlyEnemyMovement : Entity
|
||||||
{
|
{
|
||||||
if (playerObject != null)
|
if (playerObject != null)
|
||||||
{
|
{
|
||||||
// 1. 현재 위치와 플레이어 위치 사이의 거리를 계산
|
|
||||||
float distance = Vector3.Distance(transform.position, playerObject.transform.position);
|
float distance = Vector3.Distance(transform.position, playerObject.transform.position);
|
||||||
|
|
||||||
if (distance <= detectionRange)
|
if (distance <= detectionRange)
|
||||||
{
|
{
|
||||||
SetAgentPosition(); // 추격 시작
|
MoveTowardsPlayer();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// 범위 밖이라면 이동을 멈춤
|
|
||||||
if (!agent.isStopped)
|
|
||||||
{
|
|
||||||
agent.ResetPath();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetAgentPosition()
|
private void MoveTowardsPlayer()
|
||||||
{
|
{
|
||||||
if (!agent.isActiveAndEnabled || !agent.isOnNavMesh)
|
Vector3 direction = (playerObject.transform.position - transform.position).normalized;
|
||||||
|
RaycastHit2D hit = Physics2D.Raycast(transform.position, direction, 1.0f, obstacleLayer);
|
||||||
|
|
||||||
|
if (hit.collider != null)
|
||||||
{
|
{
|
||||||
return;
|
Vector2 tangent = Vector2.Perpendicular(hit.normal);
|
||||||
|
direction = Vector3.Lerp(direction, tangent, 0.5f).normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
transform.position += direction * moveSpeed * Time.deltaTime;
|
||||||
|
|
||||||
|
if (direction.x != 0)
|
||||||
|
{
|
||||||
|
transform.localScale = new Vector3(direction.x > 0 ? 1 : -1, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 targetPos = playerObject.transform.position;
|
|
||||||
agent.SetDestination(new Vector3(targetPos.x, targetPos.y));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDrawGizmosSelected()
|
private void OnDrawGizmosSelected()
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,11 @@ public class GroundEnemyMovement : Entity
|
||||||
[SerializeField] private SpriteRenderer spriteRenderer;
|
[SerializeField] private SpriteRenderer spriteRenderer;
|
||||||
[SerializeField] private float Speed = 3f;
|
[SerializeField] private float Speed = 3f;
|
||||||
[SerializeField] private float startDirection = 1.5f;
|
[SerializeField] private float startDirection = 1.5f;
|
||||||
|
[SerializeField] private LayerMask terrainLayer;
|
||||||
|
|
||||||
private float currentDirection;
|
private float currentDirection;
|
||||||
private float halfWidth;
|
private float halfWidth;
|
||||||
private Vector2 movemenet;
|
private Vector2 movement;
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
|
|
@ -21,9 +22,9 @@ public class GroundEnemyMovement : Entity
|
||||||
|
|
||||||
public override void RunAI()
|
public override void RunAI()
|
||||||
{
|
{
|
||||||
movemenet.x = Speed * currentDirection;
|
movement.x = Speed * currentDirection;
|
||||||
movemenet.y = rigidBody.linearVelocity.y;
|
movement.y = rigidBody.linearVelocity.y;
|
||||||
rigidBody.linearVelocity = movemenet;
|
rigidBody.linearVelocity = movement;
|
||||||
|
|
||||||
SetDirection();
|
SetDirection();
|
||||||
}
|
}
|
||||||
|
|
@ -44,11 +45,11 @@ public class GroundEnemyMovement : Entity
|
||||||
wallDir = Vector2.left;
|
wallDir = Vector2.left;
|
||||||
}
|
}
|
||||||
|
|
||||||
RaycastHit2D cliffHit = Physics2D.Raycast(frontVec, Vector2.down, 1f, LayerMask.GetMask("Ground"));
|
RaycastHit2D cliffHit = Physics2D.Raycast(frontVec, Vector2.down, 1f, terrainLayer);
|
||||||
Debug.DrawRay(frontVec, Vector2.down * 1f, Color.green);
|
Debug.DrawRay(frontVec, Vector2.down * 1f, Color.green);
|
||||||
|
|
||||||
float wallDist = halfWidth + 0.2f;
|
float wallDist = halfWidth + 0.2f;
|
||||||
RaycastHit2D wallHit = Physics2D.Raycast(transform.position, wallDir, wallDist, LayerMask.GetMask("Ground"));
|
RaycastHit2D wallHit = Physics2D.Raycast(transform.position, wallDir, wallDist, terrainLayer);
|
||||||
Debug.DrawRay(transform.position, wallDir * wallDist, Color.blue);
|
Debug.DrawRay(transform.position, wallDir * wallDist, Color.blue);
|
||||||
|
|
||||||
if (cliffHit.collider == null || wallHit.collider != null)
|
if (cliffHit.collider == null || wallHit.collider != null)
|
||||||
|
|
|
||||||
8
Assets/Scripts/Shop.meta
Normal file
8
Assets/Scripts/Shop.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3ce03408c5f65174590e62ebb43c41bb
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
"com.unity.render-pipelines.universal": "17.3.0",
|
"com.unity.render-pipelines.universal": "17.3.0",
|
||||||
"com.unity.test-framework": "1.6.0",
|
"com.unity.test-framework": "1.6.0",
|
||||||
"com.unity.timeline": "1.8.10",
|
"com.unity.timeline": "1.8.10",
|
||||||
"com.unity.ugui": "2.0.0",
|
|
||||||
"com.unity.visualscripting": "1.9.9",
|
"com.unity.visualscripting": "1.9.9",
|
||||||
"com.unity.modules.accessibility": "1.0.0",
|
"com.unity.modules.accessibility": "1.0.0",
|
||||||
"com.unity.modules.adaptiveperformance": "1.0.0",
|
"com.unity.modules.adaptiveperformance": "1.0.0",
|
||||||
|
|
|
||||||
|
|
@ -275,7 +275,7 @@
|
||||||
},
|
},
|
||||||
"com.unity.ugui": {
|
"com.unity.ugui": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"depth": 0,
|
"depth": 1,
|
||||||
"source": "builtin",
|
"source": "builtin",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"com.unity.modules.ui": "1.0.0",
|
"com.unity.modules.ui": "1.0.0",
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,12 @@
|
||||||
--- !u!19 &1
|
--- !u!19 &1
|
||||||
Physics2DSettings:
|
Physics2DSettings:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
serializedVersion: 5
|
serializedVersion: 11
|
||||||
m_Gravity: {x: 0, y: -9.81}
|
m_Gravity: {x: 0, y: -9.81}
|
||||||
m_DefaultMaterial: {fileID: 0}
|
m_DefaultMaterial: {fileID: 0}
|
||||||
m_VelocityIterations: 8
|
m_VelocityIterations: 8
|
||||||
m_PositionIterations: 3
|
m_PositionIterations: 3
|
||||||
m_VelocityThreshold: 1
|
m_BounceThreshold: 1
|
||||||
m_MaxLinearCorrection: 0.2
|
m_MaxLinearCorrection: 0.2
|
||||||
m_MaxAngularCorrection: 8
|
m_MaxAngularCorrection: 8
|
||||||
m_MaxTranslationSpeed: 100
|
m_MaxTranslationSpeed: 100
|
||||||
|
|
@ -19,6 +19,7 @@ Physics2DSettings:
|
||||||
m_LinearSleepTolerance: 0.01
|
m_LinearSleepTolerance: 0.01
|
||||||
m_AngularSleepTolerance: 2
|
m_AngularSleepTolerance: 2
|
||||||
m_DefaultContactOffset: 0.01
|
m_DefaultContactOffset: 0.01
|
||||||
|
m_ContactThreshold: 0
|
||||||
m_JobOptions:
|
m_JobOptions:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
useMultithreading: 0
|
useMultithreading: 0
|
||||||
|
|
@ -39,18 +40,18 @@ Physics2DSettings:
|
||||||
m_IslandSolverBodiesPerJob: 50
|
m_IslandSolverBodiesPerJob: 50
|
||||||
m_IslandSolverContactsPerJob: 50
|
m_IslandSolverContactsPerJob: 50
|
||||||
m_SimulationMode: 0
|
m_SimulationMode: 0
|
||||||
|
m_SimulationLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 4294967295
|
||||||
|
m_MaxSubStepCount: 4
|
||||||
|
m_MinSubStepFPS: 30
|
||||||
|
m_UseSubStepping: 0
|
||||||
|
m_UseSubStepContacts: 0
|
||||||
m_QueriesHitTriggers: 1
|
m_QueriesHitTriggers: 1
|
||||||
m_QueriesStartInColliders: 1
|
m_QueriesStartInColliders: 1
|
||||||
m_CallbacksOnDisable: 1
|
m_CallbacksOnDisable: 1
|
||||||
m_ReuseCollisionCallbacks: 1
|
m_ReuseCollisionCallbacks: 1
|
||||||
m_AutoSyncTransforms: 0
|
m_AutoSyncTransforms: 0
|
||||||
m_AlwaysShowColliders: 0
|
m_GizmoOptions: 10
|
||||||
m_ShowColliderSleep: 1
|
m_LayerCollisionMatrix: fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
|
||||||
m_ShowColliderContacts: 0
|
m_PhysicsLowLevelSettings: {fileID: 0}
|
||||||
m_ShowColliderAABB: 0
|
|
||||||
m_ContactArrowScale: 0.2
|
|
||||||
m_ColliderAwakeColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.7529412}
|
|
||||||
m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432}
|
|
||||||
m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745}
|
|
||||||
m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804}
|
|
||||||
m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
|
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,9 @@ TagManager:
|
||||||
- Water
|
- Water
|
||||||
- UI
|
- UI
|
||||||
- Enemy
|
- Enemy
|
||||||
-
|
- Destructible
|
||||||
-
|
- EnemyHitbox
|
||||||
-
|
- Player
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user