using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playercomtroller : MonoBehaviour
{
public int life = 3;
Rigidbody2D rigid2D;
public float jumpforce = 340.0f;
public float walkforce = 20.0f;
public float maxwalkspeed = 30.0f;
// Start is called before the first frame update
void Start()
{
this.rigid2D = GetComponent<Rigidbody2D>();
}
public void hit()
{
life--;
if (life == 0)
{
Dead();
}
}
public void Dead()
{
Destroy(gameObject);
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (life <= 3)
{
hit();
}
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
this.rigid2D.AddForce(transform.up * this.jumpforce);
}
int key = 0;
if (Input.GetKey(KeyCode.LeftArrow)){ key = -1; }
if (Input.GetKey(KeyCode.RightArrow)){ key = 1; }
float speedx = Mathf.Abs(this.rigid2D.velocity.x);
//플레이어 속도
if (speedx < this.maxwalkspeed)
{
this.rigid2D.AddForce(transform.right * key * this.walkforce);
}
//최대 스피드
if (key != 0)
{
transform.localScale = new Vector3(key, 1, 1);
}
}
}
코드가 개판이네 ㅋㅋ
하나하나 값 확인해봐라 rigid2D.velocity.x가 니가 상상하는 것처런 작동하냐?
print(), Debug.Log() 응용해서 값 확인해
debug는 해보고 물어보는게 맞지 ㅇㅇ
코딩 이렇게 하는거 아닌데... - dc App
뭔가 이상한데 코드가
forcemode 적용해봐