公共属性
private Rigidbody2D m_body2d;
[SerializeField] float m_speed = 4.0f;
[SerializeField] float m_jumpForce = 7.5f;
左右移动
void Update()
{
float inputX = Input.GetAxis("Horizontal");
if (inputX > 0)
transform.localScale = new Vector3(-1.0f, 1.0f, 1.0f);
else if (inputX < 0)
transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
m_body2d.velocity = new Vector2(inputX * m_speed, m_body2d.velocity.y);
}
跳
void Update()
{
if (Input.GetKeyDown("space"))
{
m_body2d.velocity = new Vector2(m_body2d.velocity.x, m_jumpForce);
}