트랜스폼
모든 게임 오브젝트가 가지고 있는 기본 컴포넌트

Vector
크기와 방향을 모두 가지는 물리적 / 수학적 개념

Vector3 ( x , y , z )

쿼터니언 Quaternion





인스펙터 창에서 변경하는건 오일러인데 내부에서는 쿼터니언으로 변환



Position
// Position을 직접적으로 변경하는 방법
Transform.position = new Vector3(x, y, z);
// Translate 함수를 이용한 축(x, y, z) 기준의 위치이동 방법
Transform.Translate(Direction * Speed);
// 선형 보간을 이용해 거리에 따라 빠르게 이동하며 천천히 감속하는 방법
Transform.position = Vector3.Lerp(StartPosition, EndPosition, Interpolation)
// 목표지점을 향해 일정한 속도로 이동하는 방법
Transform.position = Vector3.MoveTowards(transform.position, Target.Position, Speed);
Rotation
// rotation에 값을 직접 지정해 회전하는 방법
Transform.rotation = Quaternion.Euler(x, y, z);
// Rotate 함수를 이용한 회전
Transform.Rotate(Vector3.up, Speed);
// RotateAround를 이용한 중심축 기준으로 회전
Transform.RotateAround(Target.position, Vector3.up, Speed);
// LookAt을 이용한 대상을 향해 회전시키기
Transform.LookAt(Target.position);
Scale
// Scale 조절
Transform.localScale = new Vector3(x, y, z);
// lossyScale은 부모 오브젝트의 스케일에 상관 없이 자신 고유의 Scale 수치를 반환
Transform.lossyScale
Frame

GetKey
Input.GetKey() // 키 입력이 진행되는 동안 true를 반환합니다.
Input.GetKeyDown() // 키 입력이 시작되는 순간 1회만 true를 반환합니다.
Input.GetKeyUp() // 키 입력이 종료되는 순간 1회만 false를 반환합니다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(InputComponent))]
public class MoveComponent : MonoBehaviour
{
[SerializeField] private GameObject _movingPlane;
[SerializeField] private float _moveSpeed = 20;
[SerializeField] private float _xBoundValue = 2f;
[SerializeField] private float _zBoundValue = 3f;
private InputComponent _inputComponent;
private Vector3 _minWorldBounds;
private Vector3 _maxWorldBounds;
private Vector3 _playerExtents;
private void Start()
{
_inputComponent = GetComponent<InputComponent>();
SphereCollider playerColider = GetComponent<SphereCollider>();
if (playerColider != null)
{
_playerExtents = playerColider.bounds.extents;
}
if(_movingPlane != null )
{
Bounds planeBounds = _movingPlane.GetComponent<MeshRenderer>().bounds;
_minWorldBounds = planeBounds.center - planeBounds.extents;
_maxWorldBounds = planeBounds.center + planeBounds.extents;
}
}
private void Update()
{
Move();
}
private void Move()
{
Vector3 inputVec = new Vector3(_inputComponent.HorInput, 0f, _inputComponent.VerInput).normalized;
Vector3 deltaMovement = _moveSpeed * Time.deltaTime * inputVec;
Vector3 nextPosition = transform.position + deltaMovement;
float xGap = _xBoundValue * _playerExtents.x;
float zGap = _zBoundValue * _playerExtents.z;
nextPosition.x = Mathf.Clamp(nextPosition.x, _minWorldBounds.x + xGap, _maxWorldBounds.x - xGap);
nextPosition.z = Mathf.Clamp(nextPosition.z, _minWorldBounds.z + zGap, _maxWorldBounds.z - zGap);
transform.position = nextPosition;
}
}