대충 사인파로 점프하는거 구현한건데
점프함수를 그냥 업데이트에 넣으려고 뜯어고치다가 이상이 생겼어
public class PlayerJump : MonoBehaviour
{
public bool JumpStop = false;
private GameObject PlayerOb; private Transform PTr;
public float JumpSpeed = 1.0f;
public float height = 1.0f;
[SerializeField]
private float LinerVar = 0.0f;
[SerializeField]
private float LinerY = 0.0f;
void Start()
{
PlayerOb = this.gameObject;
PTr = PlayerOb.GetComponent<Transform>();
}
void Update()
{
Vector2 PlayerPos = PTr.position;
//Debug.Log(PlayerPos + "\n");
if (Input.GetKeyDown(KeyCode.Space)) JumpStop = true;
if (Input.GetKeyDown(KeyCode.Space)) Debug.Log("무야호~~~");
if (Input.GetKeyDown(KeyCode.LeftShift)) JumpStop = false;
if (JumpStop == false) {
LinerVar += Time.deltaTime * JumpSpeed;
LinerY = Mathf.Abs(Mathf.Sin(LinerVar));
//Debug.Log(y + "\n");
//PTr.position = new Vector2(0, LinerY) * height;
Vector2 PtrPos = YTranslate(PTr.position, 0.0f, LinerY, height);
PTr.position = PtrPos;
if (LinerVar >= 1)
{
if (LinerY <= 0.01)
{
JumpStop = true;
LinerVar = 0;
}
}
};
}
private Vector2 YTranslate(Vector2 Pos, float x, float y, float Mul)
{
Pos = new Vector2(x, y) * Mul;
return Pos;
}
}
무야호는 나오는데 애가 점프를안해...
점프함수였을땐 잘만했는데 왜 이럴까
jumpstop이 true가 되면 점프하고 싶은거 맞지? 근데 밑에는 jumpstop==false 여야 점프 코드가 실행되네 - dc App
어 뭐야 왜 반대가됬지 떙큐