본문 바로가기

배우고 싶은거/유니티

Unity Obstacle Course

반응형

plane

 

cube(Player)

 

c#(Mover)

 

material

=====================

c# 

start() -> 시작 시 한번 실행

update() -> frame 별로 실행(틱)

 

transform.Translate(x,y,z) -> 좌표를 x,y,z 만큼 더한 곳으로 이동

                                          -> 소수점 쓰려면 뒤에 f 붙이기 0.01f

 

변수 앞에 [SerializeField] 붙이면 Inspector에 추가됨

Inspector에서 바꾸는 값은 스크립트에 반영되지 않음

 

project settings > input manager에서  입력값 설정(방향키 등)

 

Input.GetAxis("Horizontal")

Input.GetAxis("Verticle")

 

update()는 컴퓨터 사양별로 속도가 다를 수 있음

Time.deltaTime으로 일관화 가능(frame rate independent)

 

Input.GetAxis("Horizontal") * Time.deltaTime;

 

Cinemachine -> Main Camera에 virtual camera 적용

(window > package manager > Unity registry 에서 cinemachine 찾아서 install)

 

components > cinemachine > create virtual camera

 

mesh renderer 끄면 안보임, box collider는 아직 있음 

 

add component > rigidbody를 하면 물리적 특성이 생김 - 중력, 충돌 등 

 

void OnCollisionEnter(Collision other) 콜백함수

{

     GetComponent<MeshRenderer>().material.color = Color.red;

}

 

Debug.Log("로그 입력");

 

Time.time -> 누적 시간

 

start()에서

GetComponent<MeshRenderer>().enabled = false;

GetComponent<Rigidbody>().useGravity = false;

update()에서 true로 설정해주면

시작 후에 나타나서 허공에서 떨어지는 효과 가능

 

자주 접근하는 객체를 변수로 따로 저장해두면 캐싱 효과

 

Tag를 사용해서 이름을 저장해두면 객체 구분 가능

 

transform.Rotate(x, y, z);

 

 

 

 

반응형

'배우고 싶은거 > 유니티' 카테고리의 다른 글

Unity 메모  (0) 2024.05.26
Unity 유데미  (0) 2024.05.26