플레이어 몬스터에 충돌 시 피격 효과(반투명) 체력 감소 코드 추가
This commit is contained in:
		@@ -80,14 +80,14 @@ public class PlayerMove : MonoBehaviour
 | 
			
		||||
        if (collision.gameObject.tag == "Enemy")
 | 
			
		||||
        {
 | 
			
		||||
            // 적과 충돌했을 때
 | 
			
		||||
            OnDameged();
 | 
			
		||||
            OnDameged(collision.transform.position);
 | 
			
		||||
            Debug.Log("플레이어가 맞았습니다.");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void OnDameged()
 | 
			
		||||
    void OnDameged(Vector2 targetPosition)
 | 
			
		||||
    {
 | 
			
		||||
        // 적과 충돌 후 1초 무적 ( 11번 레이어 PlayerDamaged로 변경 )
 | 
			
		||||
        // 적과 충돌 후 무적 ( 11번 레이어 PlayerDamaged로 변경 )
 | 
			
		||||
        // 물리 설정에서 PlayerDamaged 레이어와 Enemy 레이어가 충돌하지 않도록 설정함
 | 
			
		||||
        gameObject.layer = 11;
 | 
			
		||||
        
 | 
			
		||||
@@ -96,5 +96,25 @@ public class PlayerMove : MonoBehaviour
 | 
			
		||||
        
 | 
			
		||||
        // 무적 표시
 | 
			
		||||
        _spriteRenderer.color = new Color(1,1,1,0.5f); // 플레이어 반투명
 | 
			
		||||
        
 | 
			
		||||
        // 적과의 충돌(피격 시) 뒤로 밀려남
 | 
			
		||||
        int direction = transform.position.x - targetPosition.x > 0 ? 1 : -1; // 적과의 상대 위치에 따라 방향 결정
 | 
			
		||||
        if (direction == -1)
 | 
			
		||||
        {
 | 
			
		||||
            _rigidBody.AddForce(Vector2.left * 5, ForceMode2D.Impulse);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            _rigidBody.AddForce(Vector2.right * 5, ForceMode2D.Impulse);
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        Invoke("OffDamaeged", 1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void OffDamaeged()
 | 
			
		||||
    {
 | 
			
		||||
        gameObject.layer = 10; 
 | 
			
		||||
        _spriteRenderer.color = new Color(1,1,1,1); // 플레이어 반투명
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user