Unity Camera 自旋及沿自身坐标系方向移动(一)
void Update () {
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
if (Input.GetKey(KeyCode.J))
{
transform.Rotate(-Vector3.up * Time.deltaTime * 50f, Space.World);
}
if (h != 0 || v != 0)
{
Vector3 targetOffset = new Vector3(h, 0, v);
float y = transform.rotation.eulerAngles.y;
Vector3 targetDirection = Quaternion.Euler(0, y, 0) * targetOffset;
transform.Translate(targetDirection * Time.deltaTime * 50, Space.World);
}
}
浙公网安备 33010602011771号