몬스터 스킬 코드 추가
This commit is contained in:
@@ -59,7 +59,7 @@ AnimatorStateMachine:
|
||||
m_ChildStates:
|
||||
- serializedVersion: 1
|
||||
m_State: {fileID: -671183861281683873}
|
||||
m_Position: {x: 200, y: 0, z: 0}
|
||||
m_Position: {x: 290, y: 60, z: 0}
|
||||
m_ChildStateMachines: []
|
||||
m_AnyStateTransitions: []
|
||||
m_EntryTransitions: []
|
||||
|
||||
@@ -33,7 +33,7 @@ AnimatorStateMachine:
|
||||
m_ChildStates:
|
||||
- serializedVersion: 1
|
||||
m_State: {fileID: 6731845507815215767}
|
||||
m_Position: {x: 200, y: 0, z: 0}
|
||||
m_Position: {x: 350, y: 80, z: 0}
|
||||
m_ChildStateMachines: []
|
||||
m_AnyStateTransitions: []
|
||||
m_EntryTransitions: []
|
||||
|
||||
@@ -12,13 +12,16 @@ GameObject:
|
||||
- component: {fileID: 2313231889635043601}
|
||||
- component: {fileID: 8906552074109778006}
|
||||
- component: {fileID: 6070165933855076790}
|
||||
- component: {fileID: 6952956518810006418}
|
||||
- component: {fileID: 1967762321234574692}
|
||||
- component: {fileID: 8413106534327317216}
|
||||
m_Layer: 0
|
||||
m_Name: SmallFire
|
||||
m_TagString: Untagged
|
||||
m_TagString: MonsterSkill
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &6011198421323057472
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -136,9 +139,65 @@ CircleCollider2D:
|
||||
m_CallbackLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_IsTrigger: 0
|
||||
m_IsTrigger: 1
|
||||
m_UsedByEffector: 0
|
||||
m_UsedByComposite: 0
|
||||
m_Offset: {x: 0, y: 0}
|
||||
serializedVersion: 2
|
||||
m_Radius: 0.16
|
||||
--- !u!50 &6952956518810006418
|
||||
Rigidbody2D:
|
||||
serializedVersion: 4
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8753046487433099813}
|
||||
m_BodyType: 1
|
||||
m_Simulated: 1
|
||||
m_UseFullKinematicContacts: 0
|
||||
m_UseAutoMass: 0
|
||||
m_Mass: 1
|
||||
m_LinearDrag: 0
|
||||
m_AngularDrag: 0.05
|
||||
m_GravityScale: 0
|
||||
m_Material: {fileID: 0}
|
||||
m_IncludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_ExcludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_Interpolate: 0
|
||||
m_SleepingMode: 1
|
||||
m_CollisionDetection: 0
|
||||
m_Constraints: 0
|
||||
--- !u!114 &1967762321234574692
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8753046487433099813}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 190405d8d5d2c0e4683121e913af8457, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
speed: 10
|
||||
damage: 1
|
||||
--- !u!111 &8413106534327317216
|
||||
Animation:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8753046487433099813}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 3
|
||||
m_Animation: {fileID: 0}
|
||||
m_Animations: []
|
||||
m_WrapMode: 0
|
||||
m_PlayAutomatically: 1
|
||||
m_AnimatePhysics: 0
|
||||
m_CullingType: 0
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0c496a90807181740b307cab80502f12
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,204 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &4487626989189845864
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 2967262963877044795}
|
||||
- component: {fileID: 4707592987925002032}
|
||||
- component: {fileID: 3973976493912083445}
|
||||
- component: {fileID: 1551178407196302141}
|
||||
- component: {fileID: 8982412197521433167}
|
||||
- component: {fileID: 2406791496712764415}
|
||||
- component: {fileID: 1339834176233971923}
|
||||
m_Layer: 0
|
||||
m_Name: SmallFire
|
||||
m_TagString: MonsterSkill
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &2967262963877044795
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 4487626989189845864}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 9.6, y: -6.82, z: 0}
|
||||
m_LocalScale: {x: 2, y: 2, z: 2}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!212 &4707592987925002032
|
||||
SpriteRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 4487626989189845864}
|
||||
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_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
|
||||
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_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 0
|
||||
m_Sprite: {fileID: 21300000, guid: dde1ef27cf5df374489b1b4a97f2b654, type: 3}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_FlipX: 0
|
||||
m_FlipY: 0
|
||||
m_DrawMode: 0
|
||||
m_Size: {x: 0.32, y: 0.2}
|
||||
m_AdaptiveModeThreshold: 0.5
|
||||
m_SpriteTileMode: 0
|
||||
m_WasSpriteAssigned: 1
|
||||
m_MaskInteraction: 0
|
||||
m_SpriteSortPoint: 0
|
||||
--- !u!95 &3973976493912083445
|
||||
Animator:
|
||||
serializedVersion: 5
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 4487626989189845864}
|
||||
m_Enabled: 1
|
||||
m_Avatar: {fileID: 0}
|
||||
m_Controller: {fileID: 9100000, guid: 49f40d358006916488d6781f3ccffff6, type: 2}
|
||||
m_CullingMode: 0
|
||||
m_UpdateMode: 0
|
||||
m_ApplyRootMotion: 0
|
||||
m_LinearVelocityBlending: 0
|
||||
m_StabilizeFeet: 0
|
||||
m_WarningMessage:
|
||||
m_HasTransformHierarchy: 1
|
||||
m_AllowConstantClipSamplingOptimization: 1
|
||||
m_KeepAnimatorStateOnDisable: 0
|
||||
m_WriteDefaultValuesOnDisable: 0
|
||||
--- !u!58 &1551178407196302141
|
||||
CircleCollider2D:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 4487626989189845864}
|
||||
m_Enabled: 1
|
||||
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: 1
|
||||
m_UsedByEffector: 0
|
||||
m_UsedByComposite: 0
|
||||
m_Offset: {x: 0, y: 0}
|
||||
serializedVersion: 2
|
||||
m_Radius: 0.16
|
||||
--- !u!50 &8982412197521433167
|
||||
Rigidbody2D:
|
||||
serializedVersion: 4
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 4487626989189845864}
|
||||
m_BodyType: 1
|
||||
m_Simulated: 1
|
||||
m_UseFullKinematicContacts: 0
|
||||
m_UseAutoMass: 0
|
||||
m_Mass: 1
|
||||
m_LinearDrag: 0
|
||||
m_AngularDrag: 0.05
|
||||
m_GravityScale: 0
|
||||
m_Material: {fileID: 0}
|
||||
m_IncludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_ExcludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_Interpolate: 0
|
||||
m_SleepingMode: 1
|
||||
m_CollisionDetection: 0
|
||||
m_Constraints: 0
|
||||
--- !u!114 &2406791496712764415
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 4487626989189845864}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 190405d8d5d2c0e4683121e913af8457, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
speed: 1
|
||||
damage: 1
|
||||
_spriteRenderer: {fileID: 0}
|
||||
--- !u!111 &1339834176233971923
|
||||
Animation:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 4487626989189845864}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 3
|
||||
m_Animation: {fileID: 0}
|
||||
m_Animations: []
|
||||
m_WrapMode: 0
|
||||
m_PlayAutomatically: 1
|
||||
m_AnimatePhysics: 0
|
||||
m_CullingType: 0
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0cc74a53f6c5c944b86daaa75d4bc576
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -64294,6 +64294,38 @@ Sprite:
|
||||
m_PhysicsShape: []
|
||||
m_Bones: []
|
||||
m_SpriteID:
|
||||
--- !u!1 &1704178534 stripped
|
||||
GameObject:
|
||||
m_CorrespondingSourceObject: {fileID: 8753046487433099813, guid: 4ef2548480d47e244b87f430bbfbf910, type: 3}
|
||||
m_PrefabInstance: {fileID: 3463084450120326597}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
--- !u!50 &1704178535
|
||||
Rigidbody2D:
|
||||
serializedVersion: 4
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1704178534}
|
||||
m_BodyType: 1
|
||||
m_Simulated: 1
|
||||
m_UseFullKinematicContacts: 0
|
||||
m_UseAutoMass: 0
|
||||
m_Mass: 1
|
||||
m_LinearDrag: 0
|
||||
m_AngularDrag: 0.05
|
||||
m_GravityScale: 1
|
||||
m_Material: {fileID: 0}
|
||||
m_IncludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_ExcludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_Interpolate: 0
|
||||
m_SleepingMode: 1
|
||||
m_CollisionDetection: 0
|
||||
m_Constraints: 0
|
||||
--- !u!114 &1709543420
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -77173,10 +77205,22 @@ PrefabInstance:
|
||||
propertyPath: m_LocalEulerAnglesHint.z
|
||||
value: 90
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6302599676933473050, guid: 38634a6f4f9850d47baa381790643b17, type: 3}
|
||||
propertyPath: m_SortingLayer
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6302599676933473050, guid: 38634a6f4f9850d47baa381790643b17, type: 3}
|
||||
propertyPath: m_SortingLayerID
|
||||
value: -2014068629
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7658488480574400878, guid: 38634a6f4f9850d47baa381790643b17, type: 3}
|
||||
propertyPath: m_Name
|
||||
value: DropObject
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7658488480574400878, guid: 38634a6f4f9850d47baa381790643b17, type: 3}
|
||||
propertyPath: m_IsActive
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_RemovedGameObjects: []
|
||||
m_AddedGameObjects: []
|
||||
@@ -77192,11 +77236,11 @@ PrefabInstance:
|
||||
m_Modifications:
|
||||
- target: {fileID: 6011198421323057472, guid: 4ef2548480d47e244b87f430bbfbf910, type: 3}
|
||||
propertyPath: m_LocalPosition.x
|
||||
value: 2.343256
|
||||
value: 7.507
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6011198421323057472, guid: 4ef2548480d47e244b87f430bbfbf910, type: 3}
|
||||
propertyPath: m_LocalPosition.y
|
||||
value: -6.64587
|
||||
value: -6.405
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6011198421323057472, guid: 4ef2548480d47e244b87f430bbfbf910, type: 3}
|
||||
propertyPath: m_LocalPosition.z
|
||||
@@ -77230,14 +77274,25 @@ PrefabInstance:
|
||||
propertyPath: m_LocalEulerAnglesHint.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6070165933855076790, guid: 4ef2548480d47e244b87f430bbfbf910, type: 3}
|
||||
propertyPath: m_IsTrigger
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8753046487433099813, guid: 4ef2548480d47e244b87f430bbfbf910, type: 3}
|
||||
propertyPath: m_Name
|
||||
value: SmallFire
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8753046487433099813, guid: 4ef2548480d47e244b87f430bbfbf910, type: 3}
|
||||
propertyPath: m_IsActive
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_RemovedGameObjects: []
|
||||
m_AddedGameObjects: []
|
||||
m_AddedComponents: []
|
||||
m_AddedComponents:
|
||||
- targetCorrespondingSourceObject: {fileID: 8753046487433099813, guid: 4ef2548480d47e244b87f430bbfbf910, type: 3}
|
||||
insertIndex: -1
|
||||
addedObject: {fileID: 1704178535}
|
||||
m_SourcePrefab: {fileID: 100100000, guid: 4ef2548480d47e244b87f430bbfbf910, type: 3}
|
||||
--- !u!1001 &5291620879968733237
|
||||
PrefabInstance:
|
||||
@@ -77659,11 +77714,11 @@ SceneRoots:
|
||||
- {fileID: 2131259786}
|
||||
- {fileID: 431020306}
|
||||
- {fileID: 1932526043}
|
||||
- {fileID: 3463084450120326597}
|
||||
- {fileID: 3241122426496265767}
|
||||
- {fileID: 5448443593561372940}
|
||||
- {fileID: 8606440973891989337}
|
||||
- {fileID: 6430030730871762109}
|
||||
- {fileID: 3463084450120326597}
|
||||
- {fileID: 3102516619230165340}
|
||||
- {fileID: 7890886326164678664}
|
||||
- {fileID: 656779510139692607}
|
||||
|
||||
@@ -9,14 +9,21 @@ namespace TON
|
||||
[SerializeField]
|
||||
private MonsterBase _monsterBase;
|
||||
// private bool _isDetect;
|
||||
|
||||
private GameObject skill;
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (other.CompareTag("Player"))
|
||||
{
|
||||
skill = _monsterBase.smallFirePrefab;
|
||||
GameObject newSkill = Instantiate<GameObject>(skill);
|
||||
newSkill.transform.position = other.transform.position;
|
||||
// newSkill.GetComponent<skill>().Direction = new Vector2(1, 0);
|
||||
// _monsterBase.SetTransition(new AttackState());
|
||||
|
||||
|
||||
// 플레이어 감지하면 따라가기
|
||||
_monsterBase.SetTransition(new ChasingState());
|
||||
// _monsterBase.SetTransition(new ChasingState());
|
||||
Debug.Log("감지됨");
|
||||
|
||||
}
|
||||
|
||||
@@ -68,6 +68,8 @@ namespace TON
|
||||
public float cooldown; // 스킬 쿨다운
|
||||
public float range; // 스킬 범위
|
||||
public string animationName; // 스킬 애니메이션 이름
|
||||
|
||||
public GameObject smallFirePrefab;
|
||||
|
||||
// 첫 번째 프레임 전에 호출됩니다.
|
||||
private void Start()
|
||||
@@ -213,7 +215,7 @@ namespace TON
|
||||
public void PlayerAttack()
|
||||
{
|
||||
var target = GameObject.FindGameObjectWithTag("Player");
|
||||
Attack(target);
|
||||
Attack(target);
|
||||
}
|
||||
|
||||
public void SetOppositionDirection()
|
||||
|
||||
82
Gameton-06/Assets/Gameton/Scripts/Monster/MonsterSkill.cs
Normal file
82
Gameton-06/Assets/Gameton/Scripts/Monster/MonsterSkill.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
public class MonsterSkill : MonoBehaviour
|
||||
{
|
||||
public float speed = 3;
|
||||
public float damage = 1;
|
||||
|
||||
Vector2 direction;
|
||||
Transform playerTransform; // 플레이어의 Transform을 저장할 변수
|
||||
[SerializeField] private SpriteRenderer _spriteRenderer; // 스킬의 스프라이트 렌더러
|
||||
|
||||
public Vector2 Direction
|
||||
{
|
||||
set { direction = value.normalized; }
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
_spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
|
||||
// 플레이어 태그로 플레이어 오브젝트를 찾아서 Transform 컴포넌트를 가져옴
|
||||
GameObject player = GameObject.FindGameObjectWithTag("Player");
|
||||
|
||||
if (player != null)
|
||||
{
|
||||
playerTransform = player.transform;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Player 오브젝트를 찾을 수 없습니다. 태그를 확인하세요.");
|
||||
return; // 플레이어 없으면 이후 로직 실행 중지
|
||||
}
|
||||
|
||||
SetDirection(); // 발사 방향 설정
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
transform.Translate(direction * speed * Time.deltaTime);
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
if (collision.CompareTag("Player") || collision.CompareTag("Ground"))
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
void SetDirection()
|
||||
{
|
||||
if (playerTransform == null) return; // 플레이어가 없으면 방향 설정 불가
|
||||
|
||||
// MonsterSkill과 Player의 위치 차이 계산
|
||||
Vector2 toPlayer = playerTransform.position - transform.position;
|
||||
|
||||
// 플레이어의 왼쪽/오른쪽 판별
|
||||
if (toPlayer.x < 0)
|
||||
{
|
||||
// 플레이어가 왼쪽에 있으면 왼쪽 방향으로 발사
|
||||
direction = new Vector2(-1, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 플레이어가 오른쪽에 있으면 오른쪽 방향으로 발사
|
||||
direction = new Vector2(1, 0);
|
||||
_spriteRenderer.flipX = true; // 왼쪽 방향일 때 좌우 반전
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 190405d8d5d2c0e4683121e913af8457
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -200,113 +200,142 @@ namespace TON
|
||||
}
|
||||
}
|
||||
|
||||
public class HitState : State
|
||||
public class MonsterSkillState : State
|
||||
{
|
||||
private const string AniHit = "Hit"; // 피격 애니메이션
|
||||
private const string AniAttack = "Attack"; // 공격 애니메이션
|
||||
public GameObject smallFirePrefab;
|
||||
private MonsterBase _monsterBase;
|
||||
private float _hitStunDuration = 0.5f; // 피격 경직 시간
|
||||
private float _hitStartTime;
|
||||
|
||||
|
||||
public void Enter(MonsterBase monsterBase)
|
||||
{
|
||||
_monsterBase = monsterBase;
|
||||
_hitStartTime = Time.time;
|
||||
_monsterBase.ChangeAnimationState(AniHit);
|
||||
|
||||
Debug.Log($"피격 상태 진입! 현재 HP: {_monsterBase.currentHP}");
|
||||
smallFirePrefab = _monsterBase.smallFirePrefab;
|
||||
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
// 피격 경직 시간이 지나면 이전 상태로 복귀
|
||||
if (Time.time >= _hitStartTime + _hitStunDuration)
|
||||
{
|
||||
// HP가 0 이하면 죽음 상태로 전환
|
||||
if (_monsterBase.currentHP <= 0)
|
||||
{
|
||||
_monsterBase.SetTransition(new DeadState());
|
||||
}
|
||||
else
|
||||
{
|
||||
// 플레이어가 공격 범위 내에 있으면 공격 상태로, 아니면 추적 상태로
|
||||
var target = GameObject.FindGameObjectWithTag("Player");
|
||||
if (target != null)
|
||||
{
|
||||
float distanceToTarget =
|
||||
Vector2.Distance(_monsterBase.transform.position, target.transform.position);
|
||||
if (distanceToTarget <= _monsterBase.attackRange)
|
||||
{
|
||||
_monsterBase.SetTransition(new AttackState());
|
||||
}
|
||||
else
|
||||
{
|
||||
_monsterBase.SetTransition(new ChasingState());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_monsterBase.ChangeAnimationState(AniAttack);
|
||||
|
||||
}
|
||||
|
||||
public void Exit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void CheckTransition()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class DeadState : State
|
||||
{
|
||||
private const string AniDead = "Death"; // 죽음 애니메이션
|
||||
private MonsterBase _monsterBase;
|
||||
private float _deathAnimationDuration = 1f; // 죽음 애니메이션 재생 시간
|
||||
private float _deathStartTime;
|
||||
private bool _hasTriggeredDeath = false;
|
||||
|
||||
public void Enter(MonsterBase monsterBase)
|
||||
{
|
||||
_monsterBase = monsterBase;
|
||||
_deathStartTime = Time.time;
|
||||
_monsterBase.ChangeAnimationState(AniDead);
|
||||
|
||||
// 죽음 처리 시작
|
||||
StartDeathProcess();
|
||||
}
|
||||
|
||||
private void StartDeathProcess()
|
||||
{
|
||||
if (_hasTriggeredDeath) return;
|
||||
|
||||
_hasTriggeredDeath = true;
|
||||
|
||||
// 콜라이더 비활성화
|
||||
if (_monsterBase.GetComponent<Collider2D>() != null)
|
||||
{
|
||||
_monsterBase.GetComponent<Collider2D>().enabled = false;
|
||||
}
|
||||
|
||||
Debug.Log($"몬스터 사망: {_monsterBase.name}");
|
||||
|
||||
// 여기에 경험치 드롭, 아이템 드롭 등의 로직 추가 가능
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
// 죽음 애니메이션이 끝나면 오브젝트 제거
|
||||
if (Time.time >= _deathStartTime + _deathAnimationDuration)
|
||||
{
|
||||
GameObject.Destroy(_monsterBase.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void Exit()
|
||||
{
|
||||
}
|
||||
|
||||
public void CheckTransition()
|
||||
{
|
||||
// 죽음 상태에서는 다른 상태로 전환되지 않음
|
||||
}
|
||||
}
|
||||
//
|
||||
// public class HitState : State
|
||||
// {
|
||||
// private const string AniHit = "Hit"; // 피격 애니메이션
|
||||
// private MonsterBase _monsterBase;
|
||||
// private float _hitStunDuration = 0.5f; // 피격 경직 시간
|
||||
// private float _hitStartTime;
|
||||
//
|
||||
// public void Enter(MonsterBase monsterBase)
|
||||
// {
|
||||
// _monsterBase = monsterBase;
|
||||
// _hitStartTime = Time.time;
|
||||
// _monsterBase.ChangeAnimationState(AniHit);
|
||||
//
|
||||
// Debug.Log($"피격 상태 진입! 현재 HP: {_monsterBase.currentHP}");
|
||||
// }
|
||||
//
|
||||
// public void Update()
|
||||
// {
|
||||
// // 피격 경직 시간이 지나면 이전 상태로 복귀
|
||||
// if (Time.time >= _hitStartTime + _hitStunDuration)
|
||||
// {
|
||||
// // HP가 0 이하면 죽음 상태로 전환
|
||||
// if (_monsterBase.currentHP <= 0)
|
||||
// {
|
||||
// _monsterBase.SetTransition(new DeadState());
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // 플레이어가 공격 범위 내에 있으면 공격 상태로, 아니면 추적 상태로
|
||||
// var target = GameObject.FindGameObjectWithTag("Player");
|
||||
// if (target != null)
|
||||
// {
|
||||
// float distanceToTarget =
|
||||
// Vector2.Distance(_monsterBase.transform.position, target.transform.position);
|
||||
// if (distanceToTarget <= _monsterBase.attackRange)
|
||||
// {
|
||||
// _monsterBase.SetTransition(new AttackState());
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// _monsterBase.SetTransition(new ChasingState());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void Exit()
|
||||
// {
|
||||
// }
|
||||
//
|
||||
// public void CheckTransition()
|
||||
// {
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public class DeadState : State
|
||||
// {
|
||||
// private const string AniDead = "Death"; // 죽음 애니메이션
|
||||
// private MonsterBase _monsterBase;
|
||||
// private float _deathAnimationDuration = 1f; // 죽음 애니메이션 재생 시간
|
||||
// private float _deathStartTime;
|
||||
// private bool _hasTriggeredDeath = false;
|
||||
//
|
||||
// public void Enter(MonsterBase monsterBase)
|
||||
// {
|
||||
// _monsterBase = monsterBase;
|
||||
// _deathStartTime = Time.time;
|
||||
// _monsterBase.ChangeAnimationState(AniDead);
|
||||
//
|
||||
// // 죽음 처리 시작
|
||||
// StartDeathProcess();
|
||||
// }
|
||||
//
|
||||
// private void StartDeathProcess()
|
||||
// {
|
||||
// if (_hasTriggeredDeath) return;
|
||||
//
|
||||
// _hasTriggeredDeath = true;
|
||||
//
|
||||
// // 콜라이더 비활성화
|
||||
// if (_monsterBase.GetComponent<Collider2D>() != null)
|
||||
// {
|
||||
// _monsterBase.GetComponent<Collider2D>().enabled = false;
|
||||
// }
|
||||
//
|
||||
// Debug.Log($"몬스터 사망: {_monsterBase.name}");
|
||||
//
|
||||
// // 여기에 경험치 드롭, 아이템 드롭 등의 로직 추가 가능
|
||||
// }
|
||||
//
|
||||
// public void Update()
|
||||
// {
|
||||
// // 죽음 애니메이션이 끝나면 오브젝트 제거
|
||||
// if (Time.time >= _deathStartTime + _deathAnimationDuration)
|
||||
// {
|
||||
// GameObject.Destroy(_monsterBase.gameObject);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void Exit()
|
||||
// {
|
||||
// }
|
||||
//
|
||||
// public void CheckTransition()
|
||||
// {
|
||||
// // 죽음 상태에서는 다른 상태로 전환되지 않음
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user