unity3d - 如何在 Unity Left-Right Touch Controls 中制作?
问题描述
我正在尝试在 Unity 中制作简单的左右控件,但没有成功......我想将屏幕“拆分”成两个区域,如下图所示,所以当您按下右半部分时,角色会转到右半部分。 。 我希望有一个人可以帮助我。
解决方案
这取决于您所针对的平台。您将需要以像素为单位获取屏幕宽度。
float screenWidth = Screen.width
对于 Mobile,您将在 update 方法中执行以下操作。
Touch touch = Input.GetTouch(0);
if(touch.position.x > (screenWidth/2))
{
//The User has touched on the right side of the screen
}else
{
//The user hase touched the left side of the screen
}
要为非移动平台获取此信息,只需使用 Input.mouseposition 而不是 Input.GetTouch。至于您是否还想知道如何左右移动玩家,那应该是一个不同的问题。因为运动基于 Unity 中的许多不同变量。(即 2D、3D、现实世界物理......等)。因此,如果您还需要帮助,请参阅此链接,该链接将解释一些简单的移动脚本
推荐阅读
- apache - 如何使用 Apache htaccess 重新排序 URL 参数/查询字符串?
- mysql - 为什么在尝试创建新的 SQL Server 数据库时出现连接错误?
- r - 如何遍历数据框中的变量列表,并为每个变量应用过滤器并获得加权频率表?
- json - 使用 rust 反序列化具有多个可能值的 JSON
- netsuite - 在 SuiteScript 中,您可以使用 record.submitFields 设置自定义表单字段吗?
- c# - C# windows 服务与桌面应用程序一起安装
- oracle - 处理“自动行处理 (DML)”不遵守属性中的表单编辑授权
- python - kivy:覆盖 __init__ 使子布局显示太小
- kubernetes - 如何在 linkerd 中禁用 mTLS?
- jquery - JQuery Datepicker选择禁用日期