| GetAccelerationEvent | Returns specific acceleration measurement which occurred during last frame. (Does not allocate temporary variables). |
|---|---|
| GetAxis | Returns the value of the virtual axis identified by axisName. |
| GetAxisRaw | Returns the value of the virtual axis identified by axisName with no smoothing filtering applied. |
| GetButton | Returns true while the virtual button identified by buttonName is held down. |
| GetButtonDown | Returns true during the frame the user pressed down the virtual button identified by buttonName. |
| GetButtonUp | Returns true the first frame the user releases the virtual button identified by buttonName. |
| GetJoystickNames | Returns an array of strings describing the connected joysticks. |
| GetKey | Returns true while the user holds down the key identified by name. Think auto fire. |
| GetKeyDown | Returns true during the frame the user starts pressing down the key identified by name. |
| GetKeyUp | Returns true during the frame the user releases the key identified by name. |
| GetMouseButton | Returns whether the given mouse button is held down. |
| GetMouseButtonDown | Returns true during the frame the user pressed the given mouse button. |
| GetMouseButtonUp | Returns true during the frame the user releases the given mouse button. |
| GetTouch | Returns object representing status of a specific touch. (Does not allocate temporary variables). |
| ResetInputAxes | Resets all input. After ResetInputAxes all axes return to 0 and all buttons return to 0 for one frame. |
유니티에서 사용되는 Input 함수들
위에서 알수 있듯이 여러가지 Input 함수들을 제공합니다.
버튼에는 GetButton, GetButtonUp, GetButtonDown이 있는데
Up 같은경우 버튼에서 손을땠을때 최초 한번 발동하고
Down 같은경우 버튼을 누를시에 최초 한번 발동한다.
그리고 아무것도 붙여지지 않은 함수는 버튼을 누르는동안 계속해서 발동한다.
마우스 관련함수도 마찬가지로
up은 손을땔떼, down은 누를시, 그리고 아무것도 없는 것은 누르고 있는동안 지속적으로 발동한다.
GetAxis는 Input Manager에 미리 지정된 값들이다(스트링값으로 지정된 값)
'유니티 > 스크립트' 카테고리의 다른 글
| 유니티 내의 특정 오브젝트 보이기/감추기 Or 컴포넌트 On/off (0) | 2014.01.28 |
|---|---|
| 유니티 특정 오브젝트 생성시 시간간격 두기(실행 지연 관련) (0) | 2014.01.28 |
| 유니티 키 입력 관련 input manager 클래스관련 (0) | 2014.01.28 |
| 유니티 SendMessage함수를 사용해서 다른 오브젝트의 특정 함수 호출하기 (0) | 2014.01.28 |
| 폭파 불꽃 관련 파티클 이미지 (0) | 2014.01.28 |
| 유니티의 오브젝트 크기, 위치, 색 설정하기 (0) | 2014.01.28 |
유니티내의 다른 오브젝트의 특정함수를 호출하는 방법은 여러가지가 있다.
그중 가장 간단한 방법인 SendMessage를 사용하는 방법을 배워보자.
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
void ApplyDamage(float damage) {
print(damage);
}
void Awake() {
gameObject.SendMessage("ApplyDamage", 5.0F);
}
}
이런식으로 gameObject의 ApplyDamage함수를 호출할수있다.
마찬가지로 만약 위의 Example가 할당된 오브젝트와 부딪히면 위의 ApplyDamage함수를 호출하는 함수를 만들어보겠습니다.
using UnityEngine; using System.Collections; public class Exapmle2 : MonoBehaviour { void OnTriggerEnter(Collider coll) { coll.SendMessage("ApplyDamage", 5.0F, SendMessageOptions.DontRequireReceiver); } }
큐브를 두개 만듭니다 왼쪽이 Example2 큐브, 오른쪽이 Example 큐브입니다.
각 큐브 인스펙터 값입니다. 리지드 바디 추가후 Use Gravity off 설정. 그리고 박스 콜라이더 is trigger 체크를 했습니다.
박스 콜라이더 isTrigger체크시 물체와 물체가 충돌하면 위의 OnTriggerEnter 함수가 실행됩니다.(물체에 하나만 isTrigger체크만 되도 마찬가지로 onTriggerenter 함수가 호출 됩니다.)
처음 실행시 Example에서 한번 ApplyDamage 함수가 호출되면 위처럼 물체가 서로 겹치면 onTriggerenter함수가 발동되며 coll.SendMesage에 의해서 함수가 한번더 호출 됩니다.
SendMessage()로 호출할 함수는 큰따옴표("")로 묶어서 입력하며 다음과 같은 형식으로 사용합니다.
1. <오브젝트>.SendMessage("함수명",<옵션>);
2. <오브젝트>.SendMessage("함수명", "전달인자", <옵션>);
SendMessage로 전달하는 인수는 하나만 가능하므로 여러개의 값을 전달할시에는 배열등을 사용하여 전달합니다.
옵션은 두종류가 있으며, SendMessageOptions.DontRequireReceiver 옵션은 함수의 처리 결과를 호출 프로그램에 전달할 필요가 없는 경우에 사용되며, 이 옵션은 SendMessageOptions.RequireReceiver 옵션에 비해서 실행속도가 빠르다는 장점이 있습니다.
'유니티 > 스크립트' 카테고리의 다른 글
| 유니티 특정 오브젝트 생성시 시간간격 두기(실행 지연 관련) (0) | 2014.01.28 |
|---|---|
| 유니티 키 입력 관련 input manager 클래스관련 (0) | 2014.01.28 |
| 유니티 SendMessage함수를 사용해서 다른 오브젝트의 특정 함수 호출하기 (0) | 2014.01.28 |
| 폭파 불꽃 관련 파티클 이미지 (0) | 2014.01.28 |
| 유니티의 오브젝트 크기, 위치, 색 설정하기 (0) | 2014.01.28 |
| 유니티 WorldToScreenPoint를 사용하여 좌우 이동을 제한하는 스크립트 (0) | 2014.01.28 |
'유니티 > 스크립트' 카테고리의 다른 글
| 유니티 키 입력 관련 input manager 클래스관련 (0) | 2014.01.28 |
|---|---|
| 유니티 SendMessage함수를 사용해서 다른 오브젝트의 특정 함수 호출하기 (0) | 2014.01.28 |
| 폭파 불꽃 관련 파티클 이미지 (0) | 2014.01.28 |
| 유니티의 오브젝트 크기, 위치, 색 설정하기 (0) | 2014.01.28 |
| 유니티 WorldToScreenPoint를 사용하여 좌우 이동을 제한하는 스크립트 (0) | 2014.01.28 |
| 유니티 오브젝트 키보드로 움직이기 (0) | 2014.01.28 |
Explision.unitypackage

