버튼 조작
using UnityEngine;
public class Button : MonoBehaviour
{
void Update()
{
if (Input.anyKeyDown) {
Debug.Log("플레이어가 아무 키를 눌렀습니다.");
}
// Return 이 Enter임
// if (Input.GetKeyDown(KeyCode.Return)) {
// Debug.Log("아이템을 구입하였습니다.");
// }
// if (Input.GetKey(KeyCode.LeftArrow)) {
// Debug.Log("왼쪽으로 이동 중.");
// }
// if (Input.GetKeyUp(KeyCode.RightArrow)) {
// Debug.Log("오른쪽으로 이동 중.");
// }
// // 0 이 좌클릭 1이 우클릭
// if (Input.GetMouseButtonDown(0))
// Debug.Log("미사일 발사!");
// if (Input.GetMouseButton(0))
// Debug.Log("미사일 모으는 중...");
// if (Input.GetMouseButtonUp(0))
// Debug.Log("슈퍼 미사일 발사!");
// if (Input.GetButtonDown("Fire1")) {
// Debug.Log("Fire1!!");
// }
// if (Input.GetButton("Fire1")) {
// Debug.Log("점프 모으는 중");
// }
// if (Input.GetButtonUp("Fire1")) {
// Debug.Log("슈퍼 점프!");
// }
if (Input.GetButton("Horizontal")) {
Debug.Log("횡 이동중..." + Input.GetAxisRaw("Horizontal"));
}
if (Input.GetButton("Vertical")) {
Debug.Log("종 이동중..." + Input.GetAxisRaw("Vertical"));
}
}
}
오브젝트 이동
using UnityEngine;
public class Move : MonoBehaviour
{
Vector3 target = new Vector3(-3.65f, 2.52f, -0.12f);
void Update()
{
// 1. Move Toward (세번째 인자값이 클수록 빠르다)
// transform.position = Vector3.MoveTowards(transform.position, target, 1f);
// 2. Smooth Damp (네번째 인자값이 작을수록 빠르다)
// Vector3 velo = Vector3.zero;
// transform.position = Vector3.SmoothDamp(transform.position, target, ref velo, 0.1f);
// 3. Lerp (선형보간) (세번째 인자값이 작을수록 빠르다)
// transform.position = Vector3.Lerp(transform.position, target, 0.01f);
// 4. SLerp (구면보간) (세번째 인자값이 클수록 빠르다)
// transform.position = Vector3.Slerp(transform.position, target, 0.01f);
}
}
물체 필수 요소 (Component)
| Component | 역할 | 설명 |
|---|---|---|
| Mesh | 형태(3D 모델) | 오브젝트의 모양을 정의 |
| Material | 표면 특성 | 색상, 텍스처, 광원 효과 등 |
| Collider | 충돌 감지 | 충돌을 인식하지만 실제 움직이지 않음 |
| Rigidbody | 물리 엔진 | 중력, 힘, 충돌 적용 (실제 움직이게 함) |
| Physics Material | 마찰/반동 조절 | 공이 튀거나 얼음 위에서 미끄러지게 설정 가능 |
Mesh & Material → 모양과 색상 정의 Collider & Rigidbody → 충돌 감지 및 물리 효과 적용 Physics Material → 마찰력 및 반발력 조절 (튕기거나 미끄러짐 등)
