회원 로그인
|
커스텀 함수 (with Unity)
커스텀 함수
커스텀 함수의 작성 방법
리턴 타입을 지정 해주는 것이 중요
유니티에서 한번 보자.<
C#과 다른 부분 없이 Unity 스크립팅 기반으로 작성 됨 |
커스텀 함수의 작성 방법
//간단 예제 //1. 전역 변수 currentAmount 선언 float currentAmount; //실수 리턴값이 있기 때문에 float로 함수 선언 float DoSums(){ //2. 실수형 변수 amount에 5.0f + 55.8f 대치 float amount = 5.0f + 55.8f; //3. amount 값 리턴 return amount; } void Update(){ if(Input.GetKeyUp(KeyCode.A)) { //4. DoSums() 함수의 리턴값을 currentAmount 변수에 대치 currentAmount = DoSums(); //5. currentAmount 출력 print(currentAmount); } } // 결과는 60.8**currentAmount 변수와 DoSums()함수의 리턴 타입이 float로 일치해야 함
유니티에서 한번 보자.<
//커스텀 함수 예제 using UnityEngine; using System.Collections; public class sample : MonoBehaviour { //전역 변수 indexNumber, myName 선언 public int indexNumber = 10; public string myName = "Gomdol"; // Use this for initialization //게임 실행과 동시에 함수 실행 void Start () { // ShowMyName() 함수 실행 ShowMyName(); //리턴 함수 Calculate()를 numberIGot에 대치 int numberIGot = Calculate(); Debug.Log (numberIGot); } //정수형 리턴 함수 int Calculate() { int numberA = 10; int numberB = 20; int sum = numberA + numberB; return sum; } void ShowMyName() { //전역변수 myName 출력 Debug.Log (myName); //hello 출력 Debug.Log ("hello"); } // Update is called once per frame void Update () { } }
댓글 0개
| 엮인글 0개
285개(13/15페이지)
번호 | 제목 | 글쓴이 | 조회 | 날짜 |
---|---|---|---|---|
45 | [VisualStudio] Visual Studio 2010 Express 다운로드 | 푸딩뱃살 | 2885 | 2014.01.06 17:44 |
44 | [C#] 비교 연산자 | 푸딩뱃살 | 2891 | 2013.12.29 01:35 |
43 | [C#] 산술 연산자 | 푸딩뱃살 | 3646 | 2013.12.26 00:38 |
42 | [C#] 열거형 | 푸딩뱃살 | 2181 | 2013.12.25 01:29 |
41 | [C#] 다차원 배열 - 재그 배열 | 푸딩뱃살 | 2902 | 2013.12.21 18:36 |
40 | [C#] 다차원 배열 | 푸딩뱃살 | 2662 | 2013.12.21 15:55 |
39 | [C#] 배열(Array) | 푸딩뱃살 | 2254 | 2013.12.19 11:53 |
38 | [C#] 데이터 타입과 변수 | 푸딩뱃살 | 3801 | 2013.12.12 14:04 |
37 | [C#] 기본 구조 | 푸딩뱃살 | 2088 | 2013.12.12 10:11 |
36 | [C#] 키워드 (예약어) | 푸딩뱃살 | 3408 | 2013.12.11 13:59 |
35 | [C#] ILSpy - C# Decompiler [1+1] | 푸딩뱃살 | 5946 | 2013.11.24 14:47 |
34 | [Python] PyQt4 - Toolbar 예제 | 푸딩뱃살 | 3373 | 2013.11.12 10:19 |
33 | [C#] 반복문 - for (with Unity) | 푸딩뱃살 | 4981 | 2013.08.14 01:26 |
32 | [C#] 다중 조건문 &&(and), ||(or) (with Unity) | 푸딩뱃살 | 12593 | 2013.08.14 01:15 |
31 | [C#] 조건문 - if else (with Unity) | 푸딩뱃살 | 4582 | 2013.08.14 01:00 |
30 | [C#] 함수의 인자 (with Unity) | 푸딩뱃살 | 3709 | 2013.08.14 00:47 |
>> | [C#] 커스텀 함수 (with Unity) | 푸딩뱃살 | 3704 | 2013.08.13 22:50 |
28 | [C#] 함수 (with Unity) | 푸딩뱃살 | 3621 | 2013.08.13 01:08 |
27 | [C#] 변수 선언 (with Unity) | 푸딩뱃살 | 2987 | 2013.08.06 23:27 |
26 | [C#] 커맨드 (with Unity) | 푸딩뱃살 | 2499 | 2013.08.06 00:13 |