using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
private Transform tr;
// Start is called before the first frame update
void Start()
{
Debug.Log("Update함수 이전에 한번만 호출됨");
this.tr = this.GetComponent<Transform>();
}
// Update is called once per frame
void Update()
{
//float h = Input.GetAxis("Horizontal"); // -1 ... 1
//float v = Input.GetAxis("Vertical"); // -1 ... 1
float h = Input.GetAxisRaw("Horizontal"); // -1 ... 1
float v = Input.GetAxisRaw("Vertical"); // -1 ... 1
//this.transform.position += new Vector3(0, 0, 1);
//this.tr.Translate(Vector3.forward * 1f * v * Time.deltaTime);
Vector3 moveDir = (Vector3.forward * v) + (Vector3.right * h);
this.tr.Translate(moveDir.normalized * 3f * Time.deltaTime);
}
}
'유니티 심화' 카테고리의 다른 글
Joystick, 앞 뒤 왼 오 애니메이션, 마우스 드래그해서 시야 옮기기 (0) | 2023.08.17 |
---|---|
SpaceShooter2D - 스페이스바 눌러서 총쏘기 (0) | 2023.08.17 |
절대강좌 유니티 - Chapter01 [챕터1] (0) | 2023.08.16 |
SpaceShooter2D - 움직이기, 가두기, 애니메이션(오른쪽,왼쪽,센터) (0) | 2023.08.16 |
SetParent (0) | 2023.08.16 |