블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2737)
Unity3D (817)
Script (91)
Extensions (14)
Effect (3)
NGUI (77)
UGUI (8)
Physics (2)
Shader (36)
Math (1)
Design Pattern (2)
Xml (1)
Tips (200)
Link (22)
World (1)
AssetBundle (25)
Mecanim (2)
Plugins (70)
Trouble Shooting (68)
Encrypt (7)
LightMap (4)
Shadow (4)
Editor (8)
Crash Report (3)
Utility (9)
UnityVS (2)
Facebook SDK (2)
iTween (3)
Font (11)
Ad (14)
Photon (2)
IAP (1)
Google (8)
Android (45)
iOS (41)
Programming (474)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (58)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (53)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday
04-25 09:56

Random.Range() 함수는 

Random.Range(0, max);

했을 때, 0~(max-1)의 랜덤 값을 반환합니다.

개인적인 생각으로는 유니티는 리스트등의 개수를 받아서 인덱스로 바로 쓸 수 있도록 하려는 목적 같아 보입니다만..
( C#은 Count, Length등 대부분 배열에서 프로퍼티로 개수를 반환하고 있습니다. [예] Random.Range(0, List.Count); )



아무튼 max값은 반환하지 않습니다.

이런 이유로 NGUI는 NGUITools.cs 스크립트에 보시면

static public int RandomRange (int min, int max)
{
if (min == max) return min;
return UnityEngine.Random.Range(min, max + 1);
}

이렇게 max에 +1을 일부러 하고 있는 랜덤 함수를 직접 만들어서 쓰고 있습니다.

랜덤 함수를 사용할 때는 max값이 나와야 되는지 마는지 한 번 생각해보고 쓰는 게 좋을 것 같습니다.


P.s. 제가 처음에 Random.Range() 함수를 쓰면서 입력한 max값이 안나오는 것 같아서 확인해보고 올려봅니다.
       아시는 분들은 다들 아시고 쓰시겠지만, 혹시나 모르시는 분들을 위해 올려봅니다.


[추가]
새싹1단계 Sanoke 2013.05.22 15:25:32 댓글달기 신고
추가적으로... 
함수 파라미터가 int일 경우는 max값이 안나오는 게 맞구요 

static function Range (min : int, max : int) : int 
Description - 
Returns a random integer number between min [inclusive] and max [exclusive] (Read Only). 

float일 경우에는 max값이 나옵니다. 

static function Range (min : float, max : float) : float 
Description - 
Returns a random float number between and min [inclusive] and max [inclusive] (Read Only).

반응형

'Unity3D > Tips' 카테고리의 다른 글

Max Texture Size of iOS Devices  (0) 2013.06.14
게임 중 일시정지 하기  (0) 2013.05.30
유니티 소소한 TIP  (0) 2013.04.05
How to get SceneView Camera?  (0) 2013.03.25
EditorWindow에서 마우스/키보드 입력 체크  (2) 2013.03.22
Posted by blueasa
, |

화면에 커서를 보이거나 안보이게하기

Screen.showCursor = false;



화면의 가로/세로 크기값

Screen.width

Screen.height



해상도 설정하기

void Awake() {

 Screen.SetResolution(640, 480, true);

}



해상도 정보얻어오기

public Resolution[] resolutions = Screen.resolutions;



커서가 보이지 않고 움직이지 않게하기

Screen.lockCursor = true;



프로그램 종료하기

Application.Quit();



화면 캡쳐하기 (png 파일로만 되는거 같아요. 확실치는 않음 ㅎㅎ)

Application.CaptureScreenshot("Screenshot.png");



씬데이터 로딩 체크하기

 void Update() {

        if (Application.CanStreamedLevelBeLoaded(1))

            Application.LoadLevel(1);

        

    }


 

유니티 오쏘링모드에서 게임이 플레이 중인지 체크하기

Application.isPlaying




웹사이트로 링크걸기

Application.OpenURL ("http://unity3d.com/");



플랫폼(OS) 확인하기

Application.platform



실행중인 디바이스 확인하기(OS체크)

RuntimePlatform.OSXPlayer //맥

RuntimePlatform.WindowsPlayer // 윈도우

RuntimePlatform.WiiPlayer //닌텐도 위(wii)

RuntimePlatform.IPhonePlayer // 아이폰

RuntimePlatform.Android // 안드로이드

RuntimePlatform.XBOX360 // 엑스박스



PS3 //플레이스테이션



반응형
Posted by blueasa
, |

아래 둘 중 하나인 듯..


UnityEditor.SceneView.currentDrawingSceneView.camera


or


UnityEditor.SceneView.lastActiveSceneView.camera



참조 : http://forum.unity3d.com/threads/64920-Moving-scene-view-camera-from-editor-script?highlight=scene+view+camera



반응형
Posted by blueasa
, |

EditorWindow에서 Input 클래스는 안먹히는가 보다.

(참조 : http://answers.unity3d.com/questions/15067/input-in-editor-scripts.html)

그래서 대신 사용하는 게 Event 클래스..



Event


A UnityGUI event.

Events correspond to user input (key presses, mouse actions), or are UnityGUI layout or rendering events.

For each event OnGUI is called in the scripts; so OnGUI is potentially called multiple times per frame. Event.current corresponds to "current" event inside OnGUI call.

See Also: GUI Scripting Guide, EventType.

Variables
rawType

type

The type of event.

mousePosition

The mouse position.

delta

The relative movement of the mouse compared to last event.

button

Which mouse button was pressed.

modifiers

Which modifier keys are held down.

clickCount

How many consecutive mouse clicks have we received.

character

The character typed.

commandName

The name of an ExecuteCommand or ValidateCommand Event.

keyCode

The raw key code for keyboard events.

shift

Is Shift held down? (Read Only)

control

Is Control key held down? (Read Only)

alt

Is Alt/Option key held down? (Read Only)

command

Is Command/Windows key held down? (Read Only)

capsLock

Is Caps Lock on? (Read Only)

numeric

Is the current keypress on the numeric keyboard? (Read Only)

functionKey

Is the current keypress a function key? (Read Only)

isKey

Is this event a keyboard event? (Read Only)

isMouse

Is this event a mouse event? (Read Only)

Functions
GetTypeForControl

Use

Use this event.

Class Variables
current

The current event that's being processed right now.

Class Functions
KeyboardEvent

Create a keyboard event.



링크 : http://docs.unity3d.com/Documentation/ScriptReference/Event.html

반응형

'Unity3D > Tips' 카테고리의 다른 글

유니티 소소한 TIP  (0) 2013.04.05
How to get SceneView Camera?  (0) 2013.03.25
비활성화 된 오브젝트 찾을 때..  (0) 2013.03.21
iOS 60프레임으로 셋팅하기  (0) 2013.03.08
씬 로딩화면  (0) 2013.03.08
Posted by blueasa
, |

비활성화 된 오브젝트를 찾을 때..

몰랐었는데 transform.FindChild() 함수가 자기 자식의 비활성 오브젝트까지 검사한다.

유용하게 쓸 것 같다.

(근데 왜 레퍼런스에는 FindChild() 함수가 안보이지..? -_-;)


1) 상위에 활성화 된 GameObject가 필요.

2) 활성화 된 상위 GameObject에서 GameObject.transform.FindChild() 함수로 비활성화 된 GameObject를 찾는다.


예) 

1 GameObject goParent; 2 Transform trInactiveObject = goParent.transform.FindChild("찾고 싶은 비활성화 된 오브젝트 이름"); 3 trInactiveObject.gameObject.SetActive(true); // 비활성 오브젝트 활성화




참조 : http://devkorea.co.kr/bbs/board.php?bo_table=m03_qna&wr_id=26759&sca=UNITY&sfl=wr_subject%7C%7Cwr_content&stx=%EB%B9%84%ED%99%9C%EC%84%B1&sop=and&currentId=44


--------------------------------------------------------------------------------------------------------


Transform.childCount;    // 바로 아래의 자식 개수(비활성화 된 자식 포함)를 반환

Transform.GetChild(int index);    // 해당 index의 자식 Transform(비활성화 된 자식 포함)을 반환

반응형

'Unity3D > Tips' 카테고리의 다른 글

How to get SceneView Camera?  (0) 2013.03.25
EditorWindow에서 마우스/키보드 입력 체크  (2) 2013.03.22
iOS 60프레임으로 셋팅하기  (0) 2013.03.08
씬 로딩화면  (0) 2013.03.08
Change MonoDevelop Line Ending  (0) 2013.03.06
Posted by blueasa
, |

원하는 프레임 속도를 설정하기 위해 Unity iOS 에 의해 생성되는 사용자의 XCode 프로젝트를 열고AppController.mm 파일을 선택합니다.

#define kFPS 30


...위의 라인이 현재의 프레임 속도를 결정합니다. 그러면 사용자는 원하는 값을 설정하기 위해 변화만 주면 됩니다. 예를 들어, define 을:-


#define kFPS 60


...위와 같이 바꾼 경우 어플리케이션이 30 FPS 대신에 60 FPS 로 랜더링 것입니다.


출처 : http://unitykoreawiki.com/index.php?n=KrMain.iphone-Optimizing-MainLoop

반응형
Posted by blueasa
, |

씬 로딩화면

Unity3D/Tips / 2013. 3. 8. 14:34

Unity Pro only


AsyncOperation async = Application.LoadLevelAsync( 씬넘버 ); 

while( !async.isDone ) 
{

    // async.progress 참조해서 로딩 게이지 출력
}


Application.LoadLevelAsync로 비동기 씬 로딩을 할 수 있구요 
- 로딩이 다 되었는지는 
async.isDone 
- 얼마나 진행이 되었는지는 
async.progress 



참조1 : http://devkorea.co.kr/bbs/board.php?bo_table=m03_qna&wr_id=25581&sca=UNITY&sfl=wr_subject%7C%7Cwr_content&stx=%EB%A1%9C%EB%94%A9%ED%99%94%EB%A9%B4&sop=and&currentId=44


참조2 : http://docs.unity3d.com/Documentation/ScriptReference/Application.LoadLevelAsync.html

반응형
Posted by blueasa
, |

Project-Solution Options-Source Code-C# Source Code-Line Endings

(need UnChecked 'Use default settings from 'Text file')


1) 


2)


3)


반응형
Posted by blueasa
, |

유니티 4.0을 설치하고 실행하면, 위와 같이 “Error loading page Couldn’t read a file:// file”이라고 나오면서 실행이 안 될 때가 있습니다. 이 문제의 원인은 한글로 된 운영체제 계정 폴더 때문인 것 같습니다. 이 문제를 해결하려면, 영어로 계정을 만들어서 실행하면 됩니다. 그리고 라이센스 처리 과정이 끝나고 나면, 다시 한글 계정으로 실행해도 됩니다.


출처 : http://sunhyeon.wordpress.com/2012/11/21/%EC%9C%A0%EB%8B%88%ED%8B%B0-4-%EC%84%A4%EC%B9%98-%ED%9B%84-%EC%8B%A4%ED%96%89-%EC%98%A4%EB%A5%98-%ED%95%B4%EA%B2%B0%ED%95%98%EA%B8%B0/


반응형

'Unity3D > Tips' 카테고리의 다른 글

씬 로딩화면  (0) 2013.03.08
Change MonoDevelop Line Ending  (0) 2013.03.06
Unity 4.x에서 이전 애니메이션 방식 사용할 때..  (0) 2013.02.06
스크립트 로딩 순서 정하는 방법  (0) 2013.02.06
Unity3d 50가지 팁  (0) 2013.02.05
Posted by blueasa
, |




FBX를 익스포트해서 유니티 4.x에 올려보면 위와 같은 메뉴가 있다.


새로 메카님이라는 애니메이션 시스템이 들어간 후, 이전 애니메이션 방식을 사용하려면


위의 메뉴에서 Legacy(기본은 Generic이 선택 돼 있다)로 바꿔줘야 된다(Apply 필수).


애니메이션 파일도 적용해 주기 위해 애니를 뽑은 FBX도 위와 같은 절차를 거친 후, anim 파일을 빼내야 된다.

반응형
Posted by blueasa
, |