EngediKimHyeYoung / Unity

0 stars 0 forks source link

캐릭터좌우로 움직이기2 - PlayController2.cs #9

Open EngediKimHyeYoung opened 2 years ago

EngediKimHyeYoung commented 2 years ago

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

public class PlayController2 : MonoBehaviour { public float speed = 0.005f; private Animator animator;

void Start()
{
    animator = GetComponent<Animator>();
}

// Update is called once per frame
void Update()
{
    if (Input.GetAxisRaw("Horizontal") < 0 || Input.GetAxisRaw("Horizontal") > 0) {
        transform.Translate(Input.GetAxisRaw("Horizontal") * speed, 0, 0);
        transform.localScale = new Vector2(Input.GetAxisRaw("Horizontal"), 1);
        animator.SetBool("Run", true);
        Debug.Log("Run");
    }
    else if (Input.GetAxisRaw("Horizontal") == 0) {
        Debug.Log("stop");
        animator.SetBool("Run", false);
    }
}

}

EngediKimHyeYoung commented 2 years ago

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

public class PlayController2 : MonoBehaviour {

void Update()
{
    if (Input.GetKeyDown(KeyCode.RightArrow))
    {
        Debug.Log("오른쪽");
    }
    if (Input.GetKeyDown(KeyCode.LeftArrow))
    {
        Debug.Log("왼쪽");
    }
    if (Input.GetKeyDown(KeyCode.UpArrow))
    {
        Debug.Log("위쪽");
    }
    if (Input.GetKeyDown(KeyCode.DownArrow))
    {
        Debug.Log("아래쪽");
    }
    if (Input.GetKeyDown(KeyCode.A))
    {
        Debug.Log("A");
    }
    if (Input.GetKeyDown(KeyCode.W))
    {
        Debug.Log("W");
    }
    if (Input.GetKeyDown(KeyCode.S))
    {
        Debug.Log("S");
    }
    if (Input.GetKeyDown(KeyCode.D))
    {
        Debug.Log("D");
    }
}

}

EngediKimHyeYoung commented 2 years ago

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

public class PlayController2 : MonoBehaviour {

void Update()
{
    // Debug.Log("수평:" + Input.GetAxisRaw("Horizontal"));
    Debug.Log("수직:" + Input.GetAxisRaw("Vertical"));

    if (Input.GetAxisRaw("Horizontal") < 0)
    {
        transform.Translate(-0.02f, 0, 0);
        transform.localScale = new Vector2(-1, 1);
    }
    if (Input.GetAxisRaw("Horizontal") > 0)
    {
        transform.Translate(0.02f, 0, 0);
        transform.localScale = new Vector2(1, 1);
    }
}

}