PlayerAttack 레이어 추가
몬스터 피격 시 반투명 효과 추가(임시) 몬스터 체력 0일때 디스트로이 추가
This commit is contained in:
		@@ -166,6 +166,7 @@ MonoBehaviour:
 | 
			
		||||
  m_Script: {fileID: 11500000, guid: 0de3500b3118bd04ebf644b811d74319, type: 3}
 | 
			
		||||
  m_Name: 
 | 
			
		||||
  m_EditorClassIdentifier: 
 | 
			
		||||
  hp: 3
 | 
			
		||||
--- !u!50 &48873539
 | 
			
		||||
Rigidbody2D:
 | 
			
		||||
  serializedVersion: 5
 | 
			
		||||
@@ -5804,6 +5805,7 @@ MonoBehaviour:
 | 
			
		||||
  m_Script: {fileID: 11500000, guid: 0de3500b3118bd04ebf644b811d74319, type: 3}
 | 
			
		||||
  m_Name: 
 | 
			
		||||
  m_EditorClassIdentifier: 
 | 
			
		||||
  hp: 3
 | 
			
		||||
--- !u!1 &1991645574
 | 
			
		||||
GameObject:
 | 
			
		||||
  m_ObjectHideFlags: 0
 | 
			
		||||
@@ -5989,7 +5991,7 @@ GameObject:
 | 
			
		||||
  - component: {fileID: 2119498365}
 | 
			
		||||
  - component: {fileID: 2119498366}
 | 
			
		||||
  - component: {fileID: 2119498367}
 | 
			
		||||
  m_Layer: 10
 | 
			
		||||
  m_Layer: 12
 | 
			
		||||
  m_Name: AttackArea
 | 
			
		||||
  m_TagString: Player
 | 
			
		||||
  m_Icon: {fileID: 0}
 | 
			
		||||
 
 | 
			
		||||
@@ -3,14 +3,56 @@ using UnityEngine;
 | 
			
		||||
public class EnemyMove : MonoBehaviour
 | 
			
		||||
{
 | 
			
		||||
    Rigidbody2D _rigidbody;
 | 
			
		||||
    SpriteRenderer _spriteRenderer;
 | 
			
		||||
    
 | 
			
		||||
    // 변수
 | 
			
		||||
    [SerializeField]
 | 
			
		||||
    public int hp = 3;
 | 
			
		||||
 | 
			
		||||
    void Awake()
 | 
			
		||||
    {
 | 
			
		||||
        _rigidbody = GetComponent<Rigidbody2D>();
 | 
			
		||||
        _spriteRenderer = GetComponentInChildren<SpriteRenderer>(); // 자식 오브젝트에 스프라이트 랜더러를 불러올때는 InChildren 사용
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void FixedUpdate()
 | 
			
		||||
    { 
 | 
			
		||||
        _rigidbody.linearVelocity = new Vector2(-1, _rigidbody.linearVelocityX);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    // 공격 판정 콜라이더에 닿았을 때 호출
 | 
			
		||||
    void OnTriggerEnter2D(Collider2D other)
 | 
			
		||||
    {
 | 
			
		||||
        if (other.gameObject.layer == LayerMask.NameToLayer("PlayerAttack"))
 | 
			
		||||
        {
 | 
			
		||||
            OnDamaged(other.transform.position);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    // 데미지 처리 메서드
 | 
			
		||||
    public void OnDamaged(Vector2 playerPosition)
 | 
			
		||||
    {
 | 
			
		||||
        hp--; // 체력 감소
 | 
			
		||||
        
 | 
			
		||||
        // 피격 시 잠시 정지
 | 
			
		||||
        _rigidbody.linearVelocity = Vector2.zero;
 | 
			
		||||
        
 | 
			
		||||
        // 반투명 효과 적용
 | 
			
		||||
        _spriteRenderer.color = new Color(1, 1, 1, 0.5f);
 | 
			
		||||
        
 | 
			
		||||
        // 일정 시간 후 원래 색상으로 돌아오는 Invoke 호출
 | 
			
		||||
        Invoke("OffDamaged", 1f);
 | 
			
		||||
        
 | 
			
		||||
        // 체력이 0 이하가 되면 파괴
 | 
			
		||||
        if (hp <= 0)
 | 
			
		||||
        {
 | 
			
		||||
            Destroy(gameObject);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    // 반투명 효과를 없애고 원래 색상으로 되돌리는 메서드
 | 
			
		||||
    void OffDamaged()
 | 
			
		||||
    {
 | 
			
		||||
        _spriteRenderer.color = new Color(1, 1, 1, 1f);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,7 @@ TagManager:
 | 
			
		||||
  - Enemy
 | 
			
		||||
  - Player
 | 
			
		||||
  - PlayerDamaged
 | 
			
		||||
  - 
 | 
			
		||||
  - PlayerAttack
 | 
			
		||||
  - 
 | 
			
		||||
  - 
 | 
			
		||||
  - 
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user