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);
}
}
이렇게 했는데 왼쪽 누르면 계속 왼쪽으로 가고 오른쪽 누르면 계속 오른쪽으로 가네요
누르는 동안만 동작하고 안 누르면 멈춘 상태면 좋겠는데...
방향키 입력이 없을때는 nowMode를 player로, vx를 0으로 줘야함
감사합니다 void FixedUpdate()에 nowMode pleyer하고 vx 0주니 됐네요
fixed 말고 그냥 update에다가 if문 키입력 없을때에다가 넣어주는게 좋음