유니티 심화

절대강좌 유니티 - SpaceShooter

다모아 2023. 8. 16. 18:18
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);
    }
}