EngediKimHyeYoung / Unity

0 stars 0 forks source link

캐릭터 좌우로 움직이기 - PlayerController.cs #7

Open EngediKimHyeYoung opened 2 years ago

EngediKimHyeYoung commented 2 years ago

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class PlayerController : MonoBehaviour { // Start is called before the first frame update void Start() { Debug.Log("hi"); }

// Update is called once per frame
void Update()
{
    if (Input.GetKeyDown(KeyCode.LeftArrow))
    {
        Debug.Log("LeftArrow");
        transform.Translate(-0.5f, 0, 0);
    }
    if (Input.GetKeyDown(KeyCode.RightArrow))
    {
        Debug.Log("RightArrow");
        transform.Translate(0.5f, 0, 0);
    }
}

}

EngediKimHyeYoung commented 2 years ago

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class PlayController : MonoBehaviour { private Animator animator; void Start() { animator = GetComponent(); }

void Update()
{
    if (Input.GetKeyDown(KeyCode.LeftArrow))
    {
        transform.Translate(-0.5f, 0, 0);
        transform.localScale = new Vector2(-1, 1);
        animator.SetBool("Run", true);
        //Debug.Log("왼쪽키를 눌렀군요");
    }
    if (Input.GetKeyDown(KeyCode.RightArrow))
    {
        transform.Translate(0.5f, 0, 0);
        transform.localScale = new Vector2(1, 1);
        animator.SetBool("Run", true);
        //Debug.Log("오른쪽키를 눌렀군요");
    }
}

}