2 回答
TA贡献1796条经验 获得超7个赞
触摸左右半屏移动的代码
void Update () {
transform.position = Vector2.MoveTowards(transform.position, targetPos, speed * Time.deltaTime);
// Detect touch event
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began)
{
if (touch.position.x > (Screen.width / 2))
{
if (transform.position.x < maxWidth)
{
targetPos = new Vector2(transform.position.x + Xincrement, transform.position.y);
transform.position = targetPos;
}
}
else {
if (transform.position.x > minWidth)
{
targetPos = new Vector2(transform.position.x - Xincrement, transform.position.y);
transform.position = targetPos;
}
}
}
}
- 2 回答
- 0 关注
- 179 浏览
添加回答
举报