회원 로그인
|
커스텀 함수 (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개(1/15페이지)
번호 | 제목 | 글쓴이 | 조회 | 날짜 |
---|---|---|---|---|
285 | [Python] 동적 import - 모듈을 변수로 받아오기 | 푸딩뱃살 | 421 | 2022.10.27 10:45 |
284 | [Python] 파이썬 3.7.7과 3.9.7의 os.path.expanduser() 차이 | 푸딩뱃살 | 466 | 2022.08.18 12:22 |
283 | [Python] error: Microsoft Visual C++ 9.0 is required. | 푸딩뱃살 | 699 | 2022.08.03 13:35 |
282 | [Python] pyscript | 푸딩뱃살 | 470 | 2022.06.09 11:21 |
281 | [Python] float is / float not is | 푸딩뱃살 | 603 | 2022.03.02 15:03 |
280 | [Python] 이터널 문자열 f | 푸딩뱃살 | 843 | 2022.01.27 16:35 |
279 | [Python] is와 ==의 차이 | 푸딩뱃살 | 488 | 2021.11.25 15:54 |
278 |
[Python] Error: ImportError: file |
푸딩뱃살 | 937 | 2021.11.16 11:24 |
277 | [Python] 파이썬 디컴파일 - uncompyle6 | 푸딩뱃살 | 785 | 2021.11.10 14:46 |
276 | [Python] 파이썬 확장자 설명 | 푸딩뱃살 | 556 | 2021.11.03 14:38 |
275 | [참고] 웹 fbx 뷰어 | 푸딩뱃살 | 475 | 2021.10.19 15:46 |
274 | [Python] enumerate() | 푸딩뱃살 | 506 | 2021.10.13 14:44 |
273 | [Python] 아나콘다에서 가상 환경 | 푸딩뱃살 | 738 | 2020.11.21 00:26 |
272 | [Python] pip로 설치 때 퍼미션 에러 | 푸딩뱃살 | 1277 | 2020.06.06 17:13 |
271 | [Python] OpenCV 10-3. 이미지 Thresholding - Otsu's Binarizatio | 푸딩뱃살 | 679 | 2020.06.05 14:01 |
270 | [Python] OpenCV 10-2. 이미지 Thresholding - Adaptive Threshold | 푸딩뱃살 | 701 | 2020.06.05 13:58 |
269 | [Python] OpenCV 10-1. 이미지 Thresholding | 푸딩뱃살 | 584 | 2020.06.05 13:56 |
268 | [Python] OpenCV 9-2. 색 추적 | 푸딩뱃살 | 786 | 2020.06.02 23:29 |
267 | [Python] OpenCV 9-1. 색공간 바꾸기 | 푸딩뱃살 | 645 | 2020.06.02 23:27 |
266 | [Python] OpenCV 8-3. 이미지 비트 연산 | 푸딩뱃살 | 535 | 2020.06.02 23:21 |