Notice
Recent Posts
Recent Comments
Link
스토리지
[3.12] 상속 예제 1 본문
public class App
{
public App()
{
SCV scv1 = new SCV();
//0.미네랄 채취, 1.가스 채취
scv1.GatherResource(0);
}
}
public class Unit
{
private float x;
private float y;
public Unit()
{
Console.WriteLine("Unit 생성자 호출");
}
public float[] GetPosition()
{
float[] arr = new float[] { this.x, this.y };
return arr;
}
public void SetPosition(float x, float y)
{
this.x = x;
this.y = y;
}
}
public class SCV : Unit
{
public enum eResource
{
Mineral,
Gas
}
public SCV()
{
Console.WriteLine("SCV 생성자 호출");
}
public void GatherResource(int resource)
{
eResource res = (eResource)resource;
if (eResource.Mineral == res)
{
Console.WriteLine("미네랄을 채취하였습니다.");
}
else
{
Console.WriteLine("가스를 채취하였습니다.");
}
}
}
상황 : SCV가 미네랄을 채취함
'Unity > 수업내용(C#)' 카테고리의 다른 글
[3.15] 배열 복습 2 - 강화 & 합성 기능추가 (0) | 2021.03.15 |
---|---|
[3.15] 배열 복습 (0) | 2021.03.15 |
[3.12] 상속 Inheritance (0) | 2021.03.12 |
[3.12] Array 연습 (0) | 2021.03.12 |
[3.12] 메소드의 키워드 (ref, out, params) (0) | 2021.03.12 |
Comments