【发布时间】:2022-01-10 14:29:09
【问题描述】:
我正在开发一款游戏,到目前为止,我允许用户通过使用计算机键盘上的上下箭头键上下移动来玩游戏。
但现在我想让用户能够在手机上通过向上或向下触摸,或者向上或向下滑动来在游戏中移动。
我正在为此使用 c#。
这是分配给播放器对象的当前代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public float playerSpeed;
private Rigidbody2D rb;
private Vector2 playerDirection;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
float directionY = Input.GetAxisRaw("Vertical");
playerDirection = new Vector2(0, directionY).normalized;
}
void FixedUpdate()
{
rb.velocity = new Vector2(0, playerDirection.y * playerSpeed);
}
}
我需要做什么才能实现这一目标?
【问题讨论】:
标签: c# unity3d game-development