c# - Ground Plane Stage 旋转子对象
问题描述
在我的项目中,我有一个带有子对象的地平面舞台。现在我想用 UI Button 旋转这个对象。如果我按住按钮,它应该旋转,如果我松开按钮,旋转应该停止。不幸的是,我无法做到这一点。
这是我的脚本:
public class RotateObject : MonoBehaviour
{
public float rotationSpeed = 45f;
public bool isPressed = false;
public void TogglePressed(bool value)
{
isPressed = !isPressed;
} //edit added missing Brace
void Update()
{
if (isPressed)
{
transform.Rotate(Vector3.up * rotationSpeed * Time.deltaTime);
}
}
}
我添加Event Trigger
了Pointer Down
和Pointer Up
按钮。该脚本附加到我的游戏对象,并且该TogglePressed
函数Pointer Down
与选中的复选框链接到Pointer Up
,此处未选中复选框。
如果我在 Unity 中测试它并单击按钮,检查器显示它可以工作,但如果我将它上传到我的手机,则对象没有旋转。
编辑:
Input.GetMouseButtonDown()
void Update()
{
if (isPressed && Input.GetMouseButtonDown(0))
{
// Same Code
}
}
Input.GetButtonDown()
void Update()
{
if(isPressed && Input.GetButtonDown("Fire1"))
{
//Same Code
}
}
编辑2:
这是我现在使用的脚本:
public class RoatateObject : MonoBehaviour
{
public float rotationSpeed = 45f;
void Update()
{
if(Input.GetMouseButtonDown(0))
{
transform.Rotate(Vector3.up * rotationSpeed * Time.deltaTime);
}
}
}
解决方案
我不确切知道是否可以在手机上识别pointerdown,您是否尝试过 Input.GetMouseButtonDown() (也在手机上触发)?
也许为了加快你的测试尝试统一远程测试本地而不是上传到你的手机
推荐阅读
- php - PHP 标头重定向到 $page2 变量
- scala - Spark 无法用奇怪的三引号解析 csv
- php - 我应该使用哪个索引来混合 WHERE 和 ORDER BY
- django - Django 管理站点重定向到错误的位置
- c# - 一次请求后的 Google Api 方向 OVER_QUERY_LIMIT
- r - 从主列表创建从 A 到 Z 的子列表
- java - 使用 Olingo V4 创建 odata 服务时出错
- sql-server - 将 csv 文件导入 SQL Server DB 时指定文本限定符
- sql - 减去两个带有主键的表
- openssl - Indy 10 客户端证书:多合一 .pem 文件?