[C#] 함수

SIYEON·2024년 5월 2일

[C#] 기본

목록 보기
2/11
post-thumbnail
  1. 기본 사용법
int intValue;

floatValue = 10.5f;

void FloatToInt()
{
	intValue = (int)floatValue;
}

void Start() {
	FloatToInt();
    
    print(intValue);
}
  1. 입력값 받기
int intValue;

floatValue = 10.5f;
floatValue2 = 20.5f;

void FloatToInt(float _parameter) // 입력 받아서 처리
{
	intValue = (int)_parameter;
    print(intValue);
}

void Start() {

	FloatToInt(floatValue);
    FloatToInt(floatValue2);

}
  1. 2개의 입력값 받기
int intValue;

floatValue = 10.5f;
floatValue2 = 20.5f;

void FloatToInt(float _parameter, float _parameter2)
{
	intValue = (int)(_parameter + _parameter2);
    print(intValue);
}

void Start() {

	FloatToInt(floatValue, floatValue2);

}
  1. 반환값이 있는 함수 생성
int intValue;

floatValue = 10.5f;
floatValue2 = 20.5f;

int FloatToInt(float _parameter, float _parameter2)
{
	return (int)(_parameter + _parameter2);
    
}

void Start() {

	print(FloatToInt(floatValue, floatValue2));

}
  1. 함수 내에서 다른 함수 호출
int intValue;

floatValue = 10.5f;
floatValue2 = 20.5f;

int FloatToInt(float _parameter, float _parameter2)
{
	return Multiply((int)(_parameter + _parameter2));
    
}

int Multiply(int _parameter)
{
	return _parameter * _parameter;
}

void Start() {

	print(FloatToInt(floatValue, floatValue2));

}
profile
Unity

0개의 댓글