본문 바로가기
{Programing}/Game Engine

unity - transform

by 탱타로케이 2021. 5. 17.

하나의 Object 의 위치, 회전, 크기 속성을 가지는 component.

Scene에 존재하는 모든 Object(UI포함)는 전부 tranform을 가짐. 

transform은 부모를 가질수 있고, 위치,회전,크기는 계단식으로 적용된다. 

 

transform.localPosition : 현재 object 의 부모 transform 에 연관되는 transform의 position

transform.position : 월드 좌표에서의 transform 의 position

position -> localposition 의 변환은 InverseTransformPoint

localposition -> position 의 변환은 TransformPoint

local~~ 는 항상 부모 object 에 연관된 속성이라고 보면 된다.

getcomponent 함수류.

이 함수들은 object에 할당된 component를 가져올수 있는 함수들.

기본적으로 함수에 같이 전달되는 템플릿에 해당하는 component를 가져오며.

가져올 object에 component가 없는경우는 실패한다.

find 함수 : 전달되는 이름과 같은 object의 transform을 반환. 단 계층구조까지 전부 탐색하지 않음. 바로 아래 자식까지만 탐색 가능.

GameObject에도 find 함수가 있으나 기능이 약간 다름.

Hand 라는 객체가 있을때, 아래 코드블럭의 주석의 내용과 같이 작동한다.

public class ExampleClass : MonoBehaviour
{
    public GameObject hand;

    void Example()
    {
        // Hand라는 이름의 GameObject를 찾아서 반환.
        hand = GameObject.Find("Hand");

        // Hand라는 이름의 GameObject를 찾아서 반환.
        // 부모 GameObject 없는 최상위 GameObject여야함.
        hand = GameObject.Find("/Hand");

        // 몬스터 아래 팔 아래 Hand라는 GameObject를 찾아서 반환.
        // 몬스터는 부모 GameObject 없는 최상위 GameObject여야함.
        hand = GameObject.Find("/Monster/Arm/Hand");

        //몬스터 아래 팔 아래 Hand라는 GameObject를 찾아서 반환.
        hand = GameObject.Find("Monster/Arm/Hand");
    }
}

sendmassage 함수 : 이 함수를 호출하면 여기에 등록된 함수를 실행.

SendMessage(string methodName, object value); : methodName - 실행할 함수명, value : 실행할 함수에 전달할 변수.

docs.unity3d.com/ScriptReference/Transform.html

 

Unity - Scripting API: Transform

Every object in a Scene has a Transform. It's used to store and manipulate the position, rotation and scale of the object. Every Transform can have a parent, which allows you to apply position, rotation and scale hierarchically. This is the hierarchy seen

docs.unity3d.com

 

'{Programing} > Game Engine' 카테고리의 다른 글

unity - lighting  (0) 2023.03.06
unity - key input 관련 내용  (0) 2021.05.12
Unity - 모바일 해상도 고정 대응.  (0) 2020.06.12
Unity - Particle  (0) 2020.06.12
Unity - GameObject Find  (0) 2020.06.09

댓글