using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class Player : MonoBehaviour
{
public Vector2 inputVec;
public float speed;
public Scanner scanner;
public Hand[] hands;
public RuntimeAnimatorController[] animCon;
public float dashSpeed;
public float defaultTime;
float dashTime;
float defaultSpeed;
bool isDash;
public float coolTime;
float waitTime;
Rigidbody2D rigid;
SpriteRenderer spriter;
Animator anim;
// Start is called before the first frame update
private void Start()
{
defaultSpeed = speed;
waitTime = coolTime;
}
void Awake()
{
rigid = GetComponent<Rigidbody2D>();
spriter = GetComponent<SpriteRenderer>();
anim = GetComponent<Animator>();
scanner = GetComponent<Scanner>();
hands = GetComponentsInChildren<Hand>(true);
}
private void OnEnable()
{
speed *= Character.Speed;
anim.runtimeAnimatorController = animCon[GameManager.instance.playerId];
}
private void FixedUpdate()
{
waitTime += Time.deltaTime;
if (!GameManager.instance.isLive)
return;
//힘을 준다
//rigid.AddForce(inputVec);
//속도 제어
//rigid.velocity = inputVec;
//위치 이동
Vector2 nextVec = inputVec * speed * Time.fixedDeltaTime;
rigid.MovePosition(rigid.position + nextVec);
if (Input.GetKey(KeyCode.LeftShift) && waitTime >= coolTime)
{
isDash = true;
}
if (dashTime <= 0)
{
defaultSpeed = speed;
if (isDash)
dashTime = defaultTime;
}
else
{
dashTime -= Time.deltaTime;
defaultSpeed = dashSpeed;
waitTime = 0f;
}
isDash = false;
}
private void OnMove(InputValue value)
{
inputVec = value.Get<Vector2>();
}
private void LateUpdate()
{
if (!GameManager.instance.isLive)
return;
anim.SetFloat("Speed",inputVec.magnitude);
if(inputVec.x != 0)
{
spriter.flipX = inputVec.x < 0;
}
}
private void OnCollisionStay2D(Collision2D collision)
{
if (!GameManager.instance.isLive)
return;
GameManager.instance.health -= Time.deltaTime * 10;
if (GameManager.instance.health < 0)
{
for (int index=2; index < transform.childCount; index++)
{
transform.GetChild(index).gameObject.SetActive(false);
}
anim.SetTrigger("Dead");
GameManager.instance.GameOver();
}
}
}
에러가 나거나 하진 않는데 쉬프트 버튼을 눌러도 작동하질 않는데 그 이유를 도저히 모르겠네요.
혹시 새로운 인풋시스템을 사용한거 때문에 그런걸까요?
기존에 만들어 둔것에 대쉬기능만 추가 하려고 하니 어디부터 고쳐야 할지를 모르겠어서 답답하네요.
fixed update에서 isdash = true 해주자마자 아래서 무조건적으로 isdash = false가 들어가는거 아님??
그런데 그런거 치곤 저거랑 똑같이쓴 다른 프로젝트에선 정상작동을 해서...
미스떼리어스...
인풋을 fixedupdate에서 받지 마셈
그냥 업데이트에서 받는게 좋을까요?
넹 inputvec처럼 받으셈
inputVec처럼 받으라는게 inputVec처럼 UnityEngine.InputSystem에서 onMove를 써서 받으라는 건가요?
그냥 Update로 바꾸니 여전히 안되서 잘 모르겠네요...
GetKeydown 이 한번 딱 인식되는거고,, fixedupdate면 fixeddeltatime으로 계산해야하는거아닌가 - dc App