728x90
간단한 컨트롤러. 박스나 캡슐 GameObject 생성 후
Component 로 붙여주기만 하면 끝
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class SimpleController : MonoBehaviour
{
private Rigidbody m_Rigidbody;
public float m_MoveSpeed = 6.0f;
private void Awake()
{
m_Rigidbody = GetComponent<Rigidbody>();
m_Rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
}
// Update is called once per frame
void Update()
{
m_Rigidbody.AddForce(0.0f, 0.0f, Input.GetAxisRaw("Vertical") * m_MoveSpeed);
m_Rigidbody.AddForce(Input.GetAxisRaw("Horizontal") * m_MoveSpeed, 0.0f, 0.0f);
}
}
728x90
'프로그래밍 > Unity' 카테고리의 다른 글
Unity 어드레서블 에셋 (0) | 2021.08.09 |
---|---|
CinemachineVirtualCamera Aim 속성 (0) | 2021.07.30 |
UGUI Particle 파티클 / Effect 이펙트 (0) | 2021.05.12 |
Unity Draw Call 유틸 (0) | 2021.04.30 |
Spine Skin Attachment (0) | 2021.04.28 |
댓글