KNU_SpaceShooter/Assets/02_Scripts/PlayerController.cs

41 lines
878 B
C#
Raw Normal View History

2024-09-11 13:45:36 +09:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
2024-09-11 14:05:43 +09:00
private float h;
private float v;
2024-09-11 14:36:34 +09:00
public float moveSpeed = 5.0f;
2024-09-11 13:45:36 +09:00
void Start()
{
}
void Update()
{
2024-09-11 14:08:25 +09:00
h = Input.GetAxis("Horizontal"); // 1차원 연속값 -1.0 ~ 0.0 ~ +1.0
2024-09-11 14:12:27 +09:00
v = Input.GetAxis("Vertical"); // -1.0f ~ 0.0f ~ +1.0f
2024-09-11 14:25:44 +09:00
2024-09-11 14:34:19 +09:00
// 벡터의 덧셈연산 => 벡터의 정규화 (Vector Normalized)
2024-09-11 14:25:44 +09:00
Vector3 moveDir = (Vector3.forward * v) + (Vector3.right * h);
2024-09-11 14:36:34 +09:00
transform.Translate(moveDir.normalized * Time.deltaTime * moveSpeed);
2024-09-11 13:45:36 +09:00
}
}
2024-09-11 13:48:55 +09:00
/*
Vector3.forward = Vector3(0, 0, 1)
Vector3.up = Vector3(0, 1, 0)
Vector3.right = Vector3(1, 0, 0)
Vector3.one = Vector3(1, 1, 1)
Vector3.zero = Vector3(0, 0, 0)
*/
2024-09-11 14:25:44 +09:00
/*
*/