【发布时间】:2016-06-12 00:01:26
【问题描述】:
我创建了一个简单的脚本来在键盘输入上移动玩家,但现在我想在触摸输入上移动玩家,我该怎么做?
这是我的代码,那么如何编辑此代码以使其正常工作?我有跳跃工作,但不知道如何移动?
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()
{
}
}
【问题讨论】:
-
你知道怎么做了吗?