Skip to content

Instantly share code, notes, and snippets.

@IJEMIN
Created May 19, 2017 15:33
Show Gist options
  • Save IJEMIN/824bcb7b0fed71818f8e7604ef8fc803 to your computer and use it in GitHub Desktop.
Save IJEMIN/824bcb7b0fed71818f8e7604ef8fc803 to your computer and use it in GitHub Desktop.
class Player: MonoBehaviour{
///// 코드 뭉치들..
public float checkRadius; // 체크할 반경
void Update() {
// 중심으로 부터 원을 그려서 겹치는 모든 콜라이더2D 들을 배열로 가져옴
Collider2D detectedColliders = Physics2D.OverlapCircle(transform.position, checkRadius);
//하나씩 순회하면서 만약에 타입 A를 가진 친구가 있다면 실행하고 나머지 코드는 무시
foreach (Collider2D target in detectedColliders)
{
if(target.GetComponent() != null)
{
target.GetComponent().HealHP();
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment