public class Player : MonoBehaviour
{
Rigidbody2D rbody; //Rigidbody2D型の変数
float axisH = 0.0f; //入力
public float speed = 3.0f;
public FixedJoystick joystick; //InspectorからJoystickを取得
// Start is called before the first frame update
void Start()
{
//Rigidbody2Dを取ってくる
rbody = this.GetComponent();
}
// Update is called once per frame
void Update()
{
// axisH = Input.GetAxisRaw("Horizontal");
axisH = joystick.Horizontal;
//向きの調整
if (axisH > 0.0f)
{
//右移動
Debug.Log("右移動");
transform.localScale = new Vector2(1, 1);
}
else if (axisH < 0.0f)
{
Debug.Log("左移動");
transform.localScale = new Vector2(-1, 1);
}
}
void FixedUpdate()
{
//速度を更新する
rbody.velocity = new Vector2(axisH * speed, rbody.velocity.y);
}
}