我創建了一個簡單的腳本來移動播放器的鍵盤輸入,但現在我想移動播放器上的觸摸輸入,我該怎麼做?Move player on Unity C#
這是我的代碼,那麼如何編輯此代碼以使其工作?我有跳躍的工作,但不知道如何做移動?
using UnityEngine;
using System.Collections;
public class MoveGround : MonoBehaviour
{
public float y = 0f;
public Rigidbody2D rb;
//public float x = 0f;
//public float z = 0f;
// Use this for initialization
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
//move function
if (Input.GetKey(KeyCode.W))
{
rb.velocity = new Vector2(0, y);
}
if (!Input.GetKey(KeyCode.W))
{
rb.velocity = new Vector2(0, 0);
}
if (Input.GetKey(KeyCode.S))
{
rb.velocity = new Vector2(0, -y);
}
//move function end
}
public void Move()
{
}
}
你知道如何去做嗎? – Kleber