다양한 객체에 접근이 필요할 때 공통 분모를 추상화하여 인터페이스 클래스를 만들어 이를 접근점으로 활용
public Interface I이름
{
void function();
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public interface IWeapon{
void Shoot(GameObject obj);
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Arrow : MonoBehaviour, IWeapon {
void Start () {
}
public void Shoot(GameObject obj)
{
Vector3 initialPosition = new Vector3 (transform.position.x, transform.position.y, 0);
GameObject bullet = Instantiate(obj) as GameObject;
bullet.transform.position = initialPosition;
}
}
'C#' 카테고리의 다른 글
EventHandler (0) | 2022.06.21 |
---|---|
프로퍼티 (0) | 2022.06.21 |
람다 (0) | 2022.06.20 |
Event (0) | 2022.06.20 |
Delegate - Action, Func (0) | 2022.06.20 |