unity api part 1 07 translate rotate from Walker Boys on Vimeo.

이번에는 이동과 회전에 대해서 알아보겠습니다. 이미 앞에서 보셨다시피 이동은 Translate 메서드를 통해서 할 수 있습니다. Rotate 또한 메서드이며 Translate과 같이 transform의 하위 레벨 입니다.

transform.Translate(0, 0, 0.003f, Space.World);

transform.Rotate(0, 5, 0);

위의 소스를 해석하자면 0.003f 값 만큼 frame당 Z축으로 이동시켜줍니다. 그리고 한가지 더 추가 된 것이 있는데 Space.World입니다. 이것이 무엇인지 궁금하시면 당연히! reference를 찾아봐야겠죠.

Space.World  

Space.World

Description

Applies transformation relative to the world coordinate system

보시다시피 Space.World값을 넣어주게 되면 world 좌표계로 변환들이 일어나게 됩니다. 여기에서는 이동이 되겠네요. 그리고 회전은 5의 값만큼 Y축의 방향으로 회전하게 되겠습니다. 물론 frame당입니다.

Posted by hp-david
,


unity api part 1 06 assigning a material color to a box from Walker Boys on Vimeo.

이번 동영상은 Cube 오브젝트에 컬러를 입히는 것을 설명합니다. 오브젝트에 컬러를 입히기 위해서는 Material이라는 클래스에 있는 color 변수를 건드려야 합니다. 앞에 장에서 처럼 reference를 통한 navigating을 할 필요가 있습니다.

동영상을 찍은 사람도 단순히 material이라는 것을 검색해서 역으로 계속해서 찾아가는 것을 보게 됩니다. 다른 모든 내용은 단순해서 그냥 넘어가고 material의 예제 소스를 보면 조금 특이한점을 보게 될 것 입니다.

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
void Example() {
renderer.material.color = Color.red;
}
}

가만 보시면 material에 바로 접근해서 값을 바꾸는 것이 아니라 상위인 renderer에서 접근하는 것을 볼 수 있습니다. 그럼 우리가 해야 할 일은 또 reference에서 renderer가 도대체 어떤 녀석인지를 알아야 하겠죠.

General functionality for all renderers.

A renderer is what makes an object appear on the screen. For any game object or component its renderer can be accessed trough a renderer property:

reference에 따르면 renderer는 "화면상에 있는 오브젝트를 보이게 한다"라고 합니다. 그리고 어떤 게임 오브젝트나 컴포넌트의 renderer이든 간에 renderer property를 통해 모두 접근이 가능하다고 하네요.

즉 저희 예제를 보면 Cube도 renderer를 가지고 있고, 우리가 원하는 것은 material의 color를 바꾸고 싶기 때문에 renderer.material.color = Color.red; 라고 소스코드를 쓰는 것입니다.


Posted by hp-david
,


unity api part 1 05 translating a box from Walker Boys on Vimeo.

이번 동영상은 translate 메서드를 통해 만들어 놓은 Cube 오브젝트를 이동시키는 것을 설명합니다. translate 메서드를 검색해 보시면...

Transform.Translate  

function Translate (translation : Vector3, relativeTo : Space = Space.Self) : void

Description

Moves the transform in the direction and distance of translation.

이라고 나옵니다. 즉, position, rotation, and scale 정보를 가진 transform을 주어진 방향으로 이동시키는 역할을 하는 것입니다. 동영상에서도 나오지만 적당한 값을 넣으면 그 방향으로 계속해서 이동하는 것을 보게 됩니다.

transform.Translate(fBoxSpeed * Time.deltaTime, 0, 0);

위의 소스는 Vector x의 방향으로 fBoxSpeed만큼의 속도에 Time.deltaTime의 시간값을 곱해서 이동을 시킵니다. Time.deltaTime에 대해 궁금하시다면 Reference를 찾아보시면 상세하게 설명이 되어있습니다. 친절하게 아래에 Copy&Paste를 했습니다!

Description

The time in seconds it took to complete the last frame (Read Only).

If you add or subtract to a value every frame chances are you should multiply with Time.deltaTime. When you multiply withTime.deltaTime you essentially express: I want to move this object 10 meters per second instead of 10 meters per frame.


Posted by hp-david
,