using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class KeyPressChangeAni : MonoBehaviour
{
public string player = ""; //대기 상태
public string left = "";
public string right = "";
string nowMode = "";
public float speed = 2;
float vx = 0;
Rigidbody2D rbody;
void Start()
{
nowMode = player;
}
// Update is called once per frame
void Update()
{
if (Input.GetKey("left"))
{
nowMode = left;
vx = -speed;
}
if (Input.GetKey("right"))
{
nowMode = right;
vx = speed;
}
}
void FixedUpdate()
{
this.GetComponent<Animator>().Play(nowMode);
this.transform.Translate(vx / 50, 0, 0);
}
}
이렇게 했는데 왼쪽 누르면 계속 왼쪽으로 가고 오른쪽 누르면 계속 오른쪽으로 가네요
누르는 동안만 동작하고 안 누르면 멈춘 상태면 좋겠는데...
(잘몰름) vx 때문인 것 같아요
키를 떼어도.. 값이 초기화 되지 않아서..?
너 뭐야
왜 내 밥줄 뺏어?