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;
public float jumppower = 4;
float vx = 0;
bool pushFlag = false;
bool jumpFlag = false;
bool groundFalg = false;
Rigidbody2D rbody;
void Start()
{
rbody = GetComponent<Rigidbody2D>();
rbody.constraints = RigidbodyConstraints2D.FreezeRotation;
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;
}
if (Input.GetKeyUp("left"))
{
nowMode = player;
vx = 0;
}
if (Input.GetKeyUp("right"))
{
nowMode = player;
vx = 0;
}
if (Input.GetKey("space")&&groundFalg)
{
if(pushFlag==false)
{
jumpFlag = true;
pushFlag = true;
}
}else
{
pushFlag = false;
}
}
void FixedUpdate()
{
rbody.velocity = new Vector2(vx, rbody.velocity.y);
this.GetComponent<Animator>().Play(nowMode);
this.transform.Translate(vx / 50, 0, 0);
if(jumpFlag)
{
jumpFlag = false;
rbody.AddForce(new Vector2(0, jumppower), ForceMode2D.Impulse);
}
}
void OnTriggerStay2D(Collider2D collision)
{
groundFalg = true;
}
void OnTriggerExit2D(Collider2D collision)
{
groundFalg = false;
}
}
귀엽네 left right 입력부분에 && 연산자와 bool 점프 변수를 이용해 보렴
감사합니다 ㅜ
첨에 이렇게 해도 오류가 나서 아니라고 생각했네요ㅜ
점프 중에는 점프 못하게 잘 했으면서 ㅋㅋㅋ
첨에 그렇게 계속 시도했는데 오류가 나길래요